Source file
src/runtime/conv_wasm_test.go
1
2
3
4
5 package runtime_test
6
7 import (
8 "testing"
9 )
10
11 var res int64
12 var ures uint64
13
14
15
16 func TestFloatTruncation(t *testing.T) {
17 testdata := []struct {
18 input float64
19 convInt64 int64
20 convUInt64 uint64
21 overflow bool
22 }{
23
24 {
25 input: 0x7fffffffffffffff,
26 convInt64: 0x7fffffffffffffff,
27 convUInt64: 0x8000000000000000,
28 },
29
30
31
32 {
33 input: 0x8000000000000000,
34 convInt64: 0x7fffffffffffffff,
35 convUInt64: 0x8000000000000000,
36 },
37 {
38 input: 0x7ffffffffffffffe,
39 convInt64: 0x7fffffffffffffff,
40 convUInt64: 0x8000000000000000,
41 },
42
43 {
44 input: -0x8000000000000000,
45 convInt64: -0x8000000000000000,
46 convUInt64: 0,
47 },
48 {
49 input: -0x8000000000000001,
50 convInt64: -0x8000000000000000,
51 convUInt64: 0,
52 },
53 {
54 input: -0x7fffffffffffffff,
55 convInt64: -0x8000000000000000,
56 convUInt64: 0,
57 },
58
59 {
60 input: 0x7ffffffffffffdff,
61 convInt64: 0x7ffffffffffffc00,
62 convUInt64: 0x7ffffffffffffc00,
63 },
64 {
65 input: 0x7ffffffffffffe00,
66 convInt64: 0x7fffffffffffffff,
67 convUInt64: 0x8000000000000000,
68 },
69 {
70 input: 0x7ffffffffffffdfe,
71 convInt64: 0x7ffffffffffffc00,
72 convUInt64: 0x7ffffffffffffc00,
73 },
74
75 {
76 input: -0x7ffffffffffffdff,
77 convInt64: -0x7ffffffffffffc00,
78 convUInt64: 0,
79 },
80 {
81 input: -0x7ffffffffffffe00,
82 convInt64: -0x8000000000000000,
83 convUInt64: 0,
84 },
85 {
86 input: -0x7ffffffffffffdfe,
87 convInt64: -0x7ffffffffffffc00,
88 convUInt64: 0,
89 },
90
91 {
92 input: 0xffffffffffffffff,
93 convInt64: 0x7fffffffffffffff,
94 convUInt64: 0xffffffffffffffff,
95 },
96 {
97 input: 0x10000000000000000,
98 convInt64: 0x7fffffffffffffff,
99 convUInt64: 0xffffffffffffffff,
100 },
101 {
102 input: 0xfffffffffffffffe,
103 convInt64: 0x7fffffffffffffff,
104 convUInt64: 0xffffffffffffffff,
105 },
106
107 {
108 input: 0xfffffffffffffbff,
109 convInt64: 0x7fffffffffffffff,
110 convUInt64: 0xfffffffffffff800,
111 },
112 {
113 input: 0xfffffffffffffc00,
114 convInt64: 0x7fffffffffffffff,
115 convUInt64: 0xffffffffffffffff,
116 },
117 {
118 input: 0xfffffffffffffbfe,
119 convInt64: 0x7fffffffffffffff,
120 convUInt64: 0xfffffffffffff800,
121 },
122 }
123 for _, item := range testdata {
124 if got, want := int64(item.input), item.convInt64; got != want {
125 t.Errorf("int64(%f): got %x, want %x", item.input, got, want)
126 }
127 if got, want := uint64(item.input), item.convUInt64; got != want {
128 t.Errorf("uint64(%f): got %x, want %x", item.input, got, want)
129 }
130 }
131 }
132
View as plain text