@@ -8,12 +8,12 @@ import (
88
99func TestToFloat8WithMode (t * testing.T ) {
1010 tests := []struct {
11- name string
12- input float32
13- mode ConversionMode
14- want Float8
15- hasErr bool
16- errMsg string
11+ name string
12+ input float32
13+ mode ConversionMode
14+ want Float8
15+ hasErr bool
16+ errMsg string
1717 }{
1818 {
1919 name : "zero" ,
@@ -44,12 +44,12 @@ func TestToFloat8WithMode(t *testing.T) {
4444 hasErr : false ,
4545 },
4646 {
47- name : "NaN in strict mode" ,
48- input : float32 (math .NaN ()),
49- mode : ModeStrict ,
50- want : 0 ,
51- hasErr : true ,
52- errMsg : "NaN not representable in float8" ,
47+ name : "NaN in strict mode" ,
48+ input : float32 (math .NaN ()),
49+ mode : ModeStrict ,
50+ want : 0 ,
51+ hasErr : true ,
52+ errMsg : "NaN not representable in float8" ,
5353 },
5454 {
5555 name : "NaN in default mode" ,
@@ -66,12 +66,12 @@ func TestToFloat8WithMode(t *testing.T) {
6666 hasErr : false ,
6767 },
6868 {
69- name : "overflow in strict mode" ,
69+ name : "overflow in strict mode" ,
7070 input : math .MaxFloat32 ,
7171 mode : ModeStrict ,
72- want : 0 ,
73- hasErr : true ,
74- errMsg : "overflow: value too large for float8" ,
72+ want : 0 ,
73+ hasErr : true ,
74+ errMsg : "overflow: value too large for float8" ,
7575 },
7676 {
7777 name : "underflow in default mode" ,
@@ -81,12 +81,12 @@ func TestToFloat8WithMode(t *testing.T) {
8181 hasErr : false ,
8282 },
8383 {
84- name : "underflow in strict mode" ,
84+ name : "underflow in strict mode" ,
8585 input : math .SmallestNonzeroFloat32 ,
8686 mode : ModeStrict ,
87- want : 0 ,
88- hasErr : true ,
89- errMsg : "underflow: value too small for float8" ,
87+ want : 0 ,
88+ hasErr : true ,
89+ errMsg : "underflow: value too small for float8" ,
9090 },
9191 {
9292 name : "denormal number" ,
@@ -135,7 +135,7 @@ func TestToFloat8WithMode(t *testing.T) {
135135 for _ , tt := range tests {
136136 t .Run (tt .name , func (t * testing.T ) {
137137 got , err := ToFloat8WithMode (tt .input , tt .mode )
138-
138+
139139 if tt .hasErr {
140140 if err == nil {
141141 t .Fatal ("expected error, got nil" )
@@ -160,7 +160,7 @@ func TestToFloat8WithMode(t *testing.T) {
160160func TestConversionTable (t * testing.T ) {
161161 // First disable any existing conversion table
162162 DisableFastConversion ()
163-
163+
164164 // Test that the table is nil initially
165165 if conversionTable != nil {
166166 t .Error ("conversionTable should be nil initially" )
@@ -169,31 +169,31 @@ func TestConversionTable(t *testing.T) {
169169 // Test EnableFastConversion
170170 t .Run ("EnableFastConversion" , func (t * testing.T ) {
171171 EnableFastConversion ()
172-
172+
173173 if conversionTable == nil {
174174 t .Error ("conversionTable should be initialized after EnableFastConversion" )
175175 }
176-
176+
177177 if len (conversionTable ) != 256 {
178178 t .Errorf ("conversionTable length = %d, want 256" , len (conversionTable ))
179179 }
180-
180+
181181 // Test a few values to ensure the table is populated correctly
182182 testValues := []struct {
183183 input int
184184 output float32
185185 skip bool // Skip comparison for values that might vary
186186 }{
187- {0x00 , 0.0 , false }, // +0.0
188- {0x80 , - 0. 0 , false }, // -0.0
189- {0x3F , 1.0 , true }, // 1.0 (approximate in float8)
190- {0xBF , - 1.0 , true }, // -1.0 (approximate in float8)
187+ {0x00 , 0.0 , false }, // +0.0
188+ {0x80 , float32 ( math . Copysign ( 0 , - 1 )), false }, // -0.0
189+ {0x3F , 1.0 , true }, // 1.0 (approximate in float8)
190+ {0xBF , - 1.0 , true }, // -1.0 (approximate in float8)
191191 {0x78 , float32 (math .Inf (1 )), false }, // +Inf (IEEE 754 E4M3FN)
192192 {0xF8 , float32 (math .Inf (- 1 )), false }, // -Inf (IEEE 754 E4M3FN)
193193 {0x7F , float32 (math .NaN ()), false }, // NaN (IEEE 754 E4M3FN)
194194 {0xFF , float32 (math .NaN ()), false }, // NaN (IEEE 754 E4M3FN)
195195 }
196-
196+
197197 for _ , tv := range testValues {
198198 if tv .skip {
199199 continue // Skip values that are approximations
@@ -208,7 +208,7 @@ func TestConversionTable(t *testing.T) {
208208 // Test DisableFastConversion
209209 t .Run ("DisableFastConversion" , func (t * testing.T ) {
210210 DisableFastConversion ()
211-
211+
212212 if conversionTable != nil {
213213 t .Error ("conversionTable should be nil after DisableFastConversion" )
214214 }
@@ -221,7 +221,7 @@ func TestParse(t *testing.T) {
221221 if err == nil {
222222 t .Fatal ("expected error from Parse, got nil" )
223223 }
224-
224+
225225 expectedErr := "float8.parse: not implemented"
226226 if err .Error () != expectedErr {
227227 t .Errorf ("unexpected error message: got %q, want %q" , err .Error (), expectedErr )
@@ -236,7 +236,7 @@ func TestToSlice32EdgeCases(t *testing.T) {
236236 if result != nil {
237237 t .Errorf ("ToSlice32([]) = %v, want nil" , result )
238238 }
239-
239+
240240 // Test non-empty slice
241241 nonEmptySlice := []Float8 {One (), FromInt (2 ), PositiveZero }
242242 result2 := ToSlice32 (nonEmptySlice )
@@ -254,12 +254,12 @@ func TestToSlice32EdgeCases(t *testing.T) {
254254// TestToFloat8WithModeEdgeCases tests edge cases in ToFloat8WithMode to achieve 100% coverage
255255func TestToFloat8WithModeEdgeCases (t * testing.T ) {
256256 tests := []struct {
257- name string
258- input float32
259- mode ConversionMode
260- want Float8
261- hasErr bool
262- errMsg string
257+ name string
258+ input float32
259+ mode ConversionMode
260+ want Float8
261+ hasErr bool
262+ errMsg string
263263 }{
264264 // Test overflow in strict mode
265265 {
@@ -309,7 +309,6 @@ func TestToFloat8WithModeEdgeCases(t *testing.T) {
309309 want : NegativeZero ,
310310 hasErr : false ,
311311 },
312-
313312 }
314313
315314 for _ , tt := range tests {
0 commit comments