@@ -425,55 +425,29 @@ func TestDebugSubnormalValues(t *testing.T) {
425425
426426func TestSqrt (t * testing.T ) {
427427 converter := NewConverter (ModeIEEE , RoundNearestEven )
428- tests := []struct {
429- input Float16
430- expected Float16
431- name string
432- }{
433- {PositiveZero , PositiveZero , "sqrt(0)" },
434- {converter .ToFloat16 (1.0 ), converter .ToFloat16 (1.0 ), "sqrt(1)" },
435- {converter .ToFloat16 (4.0 ), converter .ToFloat16 (2.0 ), "sqrt(4)" },
436- {converter .ToFloat16 (16.0 ), converter .ToFloat16 (4.0 ), "sqrt(16)" },
437- {PositiveInfinity , PositiveInfinity , "sqrt(inf)" },
438- }
439-
440- for _ , test := range tests {
441- t .Run (test .name , func (t * testing.T ) {
442- result := Sqrt (test .input )
443- if ! Equal (result , test .expected ) && ! result .IsInf (0 ) {
444- t .Errorf ("Sqrt(0x%04x) = 0x%04x, expected 0x%04x" ,
445- test .input , result , test .expected )
446- }
447- })
448- }
449- }
450-
451- func TestMathConstants (t * testing.T ) {
452- converter := NewConverter (ModeIEEE , RoundNearestEven )
453- // Just verify that constants are reasonable values
454- if E .ToFloat32 () < 2.7 || E .ToFloat32 () > 2.8 {
455- t .Errorf ("E constant seems wrong: %g" , E .ToFloat32 ())
456- }
457- if Pi .ToFloat32 () < 3.1 || Pi .ToFloat32 () > 3.2 {
458- t .Errorf ("Pi constant seems wrong: %g" , Pi .ToFloat32 ())
459- }
460- if Sqrt2 .ToFloat32 () < 1.4 || Sqrt2 .ToFloat32 () > 1.5 {
461- t .Errorf ("Sqrt2 constant seems wrong: %g" , Sqrt2 .ToFloat32 ())
428+ mathConverter := NewMathConverter (converter )
429+ // Test Sqrt
430+ sqrtResult := mathConverter .Sqrt (converter .FromFloat32 (4.0 ))
431+ if sqrtResult != converter .FromFloat32 (2.0 ) {
432+ t .Errorf ("Expected Sqrt(4.0) to be 2.0, but got %v" , sqrtResult )
462433 }
463434}
464435
465- func TestTrigFunctions (t * testing.T ) {
436+ func TestSinCosTan (t * testing.T ) {
466437 converter := NewConverter (ModeIEEE , RoundNearestEven )
467- // Test basic trigonometric identities
468- zero := PositiveZero
469- if ! Equal (Sin (zero ), zero ) {
470- t .Error ("sin(0) should be 0" )
438+ mathConverter := NewMathConverter (converter )
439+ // Test Sin, Cos, Tan
440+ sinResult := mathConverter .Sin (converter .FromFloat32 (0.0 ))
441+ if sinResult != converter .FromFloat32 (0.0 ) {
442+ t .Errorf ("Expected Sin(0.0) to be 0.0, but got %v" , sinResult )
471443 }
472- if ! Equal (Cos (zero ), converter .ToFloat16 (1.0 )) {
473- t .Error ("cos(0) should be 1" )
444+ cosResult := mathConverter .Cos (converter .FromFloat32 (0.0 ))
445+ if cosResult != converter .FromFloat32 (1.0 ) {
446+ t .Errorf ("Expected Cos(0.0) to be 1.0, but got %v" , cosResult )
474447 }
475- if ! Equal (Tan (zero ), zero ) {
476- t .Error ("tan(0) should be 0" )
448+ tanResult := mathConverter .Tan (converter .FromFloat32 (0.0 ))
449+ if tanResult != converter .FromFloat32 (0.0 ) {
450+ t .Errorf ("Expected Tan(0.0) to be 0.0, but got %v" , tanResult )
477451 }
478452}
479453
@@ -489,7 +463,7 @@ func TestToFloat64(t *testing.T) {
489463 {"negative zero" , NegativeZero , math .Copysign (0.0 , - 1.0 )},
490464 {"positive infinity" , PositiveInfinity , math .Inf (1 )},
491465 {"negative infinity" , NegativeInfinity , math .Inf (- 1 )},
492- {"quiet NaN" , converter . NaN (), math .NaN ()},
466+ {"quiet NaN" , NaN (), math .NaN ()},
493467
494468 // Normal numbers
495469 {"one" , Float16 (0x3c00 ), 1.0 },
@@ -578,8 +552,7 @@ func TestFromFloat64(t *testing.T) {
578552func TestFromFloat64WithMode (t * testing.T ) {
579553 // Test basic conversion
580554 t .Run ("basic conversion" , func (t * testing.T ) {
581- converter := NewConverter (testModeDefault , testRoundNearestEven )
582- result , err := converter .FromFloat64WithMode (1.5 )
555+ result , err := FromFloat64WithMode (1.5 , testModeDefault , testRoundNearestEven )
583556 if err != nil {
584557 t .Fatalf ("Unexpected error: %v" , err )
585558 }
@@ -591,26 +564,23 @@ func TestFromFloat64WithMode(t *testing.T) {
591564
592565 // Test strict mode with overflow
593566 t .Run ("strict mode overflow" , func (t * testing.T ) {
594- converter := NewConverter (testModeStrict , testRoundNearestEven )
595- _ , err := converter .FromFloat64WithMode (1e10 )
567+ _ , err := FromFloat64WithMode (1e10 , testModeStrict , testRoundNearestEven )
596568 if err == nil {
597569 t .Error ("Expected overflow error in strict mode" )
598570 }
599571 })
600572
601573 // Test strict mode with underflow
602574 t .Run ("strict mode underflow" , func (t * testing.T ) {
603- converter := NewConverter (testModeStrict , testRoundNearestEven )
604- _ , err := converter .FromFloat64WithMode (1e-10 )
575+ _ , err := FromFloat64WithMode (1e-10 , testModeStrict , testRoundNearestEven )
605576 if err == nil {
606577 t .Error ("Expected underflow error in strict mode" )
607578 }
608579 })
609580
610581 // Test NaN in strict mode
611582 t .Run ("strict mode NaN" , func (t * testing.T ) {
612- converter := NewConverter (testModeStrict , testRoundNearestEven )
613- _ , err := converter .FromFloat64WithMode (math .NaN ())
583+ _ , err := FromFloat64WithMode (math .NaN (), testModeStrict , testRoundNearestEven )
614584 if err == nil {
615585 t .Error ("Expected NaN error in strict mode" )
616586 }
@@ -631,8 +601,7 @@ func TestFromFloat64WithMode(t *testing.T) {
631601
632602 for _ , test := range roundingTests {
633603 t .Run (test .name , func (t * testing.T ) {
634- converter := NewConverter (testModeDefault , test .roundMode )
635- result , err := converter .FromFloat64WithMode (test .input )
604+ result , err := FromFloat64WithMode (test .input , testModeDefault , test .roundMode )
636605 if err != nil {
637606 t .Fatalf ("Unexpected error: %v" , err )
638607 }
@@ -722,8 +691,6 @@ func BenchmarkSqrt(b *testing.B) {
722691}
723692
724693
725-
726- func TestFloat16ConverterInitialization (t * testing.T ) {
727694 converter := NewConverter (ModeIEEE , RoundNearestEven )
728695 if converter == nil {
729696 t .Error ("Expected converter to be initialized, got nil" )
0 commit comments