11package float16
22
33import (
4- "fmt"
54 "math"
65)
76
@@ -187,7 +186,7 @@ func MulWithMode(a, b Float16, mode ArithmeticMode, rounding RoundingMode) (Floa
187186 }
188187
189188 // Full IEEE 754 implementation
190- return addIEEE754 (a , b , rounding )
189+ return mulIEEE754 (a , b , rounding )
191190}
192191
193192// Div performs division of two Float16 values
@@ -325,7 +324,7 @@ func DivWithMode(a, b Float16, mode ArithmeticMode, rounding RoundingMode) (Floa
325324 }
326325
327326 // Full IEEE 754 implementation
328- return addIEEE754 (a , b , rounding )
327+ return divIEEE754 (a , b , rounding )
329328}
330329
331330// IEEE 754 compliant arithmetic implementations
@@ -337,7 +336,7 @@ func addIEEE754(a, b Float16, rounding RoundingMode) (Float16, error) {
337336 f32a := a .ToFloat32 ()
338337 f32b := b .ToFloat32 ()
339338 result := f32a + f32b
340- return FromFloat32 (result ), nil
339+ return FromFloat32WithRounding (result , rounding ), nil
341340}
342341
343342// mulIEEE754 implements full IEEE 754 multiplication
@@ -347,7 +346,7 @@ func mulIEEE754(a, b Float16, rounding RoundingMode) (Float16, error) {
347346 f32a := a .ToFloat32 ()
348347 f32b := b .ToFloat32 ()
349348 result := f32a * f32b
350- return FromFloat32 (result ), nil
349+ return FromFloat32WithRounding (result , rounding ), nil
351350}
352351
353352// divIEEE754 implements full IEEE 754 division
@@ -357,9 +356,7 @@ func divIEEE754(a, b Float16, rounding RoundingMode) (Float16, error) {
357356 f32a := a .ToFloat32 ()
358357 f32b := b .ToFloat32 ()
359358 result := f32a / f32b
360-
361- // Use the provided rounding mode for the conversion back to Float16
362- return FromFloat32 (result ), nil
359+ return FromFloat32WithRounding (result , rounding ), nil
363360}
364361
365362// Comparison operations
@@ -499,12 +496,8 @@ func MulSlice(a, b []Float16) []Float16 {
499496
500497 result := make ([]Float16 , len (a ))
501498 for i := range a {
502- product := Mul (a [i ], b [i ])
503- result [i ] = product
504- // Debug print
505- fmt .Printf ("MulSlice: a[%d]=%v (0x%04X), b[%d]=%v (0x%04X), product=%v (0x%04X)\n " , i , a [i ], uint16 (a [i ]), i , b [i ], uint16 (b [i ]), product , uint16 (product ))
499+ result [i ] = Mul (a [i ], b [i ])
506500 }
507- fmt .Printf ("MulSlice: result=%v\n " , result )
508501 return result
509502}
510503
0 commit comments