@@ -3742,6 +3742,7 @@ double fma(double x, double y, double z)
3742
3742
else if (isnan (z ))
3743
3743
return 0.0 / 0.0 ;
3744
3744
3745
+ #pragma CPROVER check disable "float-overflow"
3745
3746
double x_times_y = x * y ;
3746
3747
if (
3747
3748
isinf (x_times_y ) && isinf (z ) &&
@@ -3752,8 +3753,13 @@ double fma(double x, double y, double z)
3752
3753
}
3753
3754
#pragma CPROVER check pop
3754
3755
3755
- // TODO: detect overflow (FE_OVERFLOW), return +/- __builtin_inf()
3756
+ if (isinf (x_times_y ))
3757
+ {
3758
+ feraiseexcept (FE_OVERFLOW );
3759
+ return __CPROVER_signd (x_times_y ) ? - __builtin_inf () : __builtin_inf ();
3760
+ }
3756
3761
// TODO: detect underflow (FE_UNDERFLOW), return +/- 0
3762
+
3757
3763
return x_times_y + z ;
3758
3764
}
3759
3765
@@ -3788,6 +3794,7 @@ float fmaf(float x, float y, float z)
3788
3794
else if (isnanf (z ))
3789
3795
return 0.0f / 0.0f ;
3790
3796
3797
+ #pragma CPROVER check disable "float-overflow"
3791
3798
float x_times_y = x * y ;
3792
3799
if (
3793
3800
isinff (x_times_y ) && isinff (z ) &&
@@ -3798,8 +3805,13 @@ float fmaf(float x, float y, float z)
3798
3805
}
3799
3806
#pragma CPROVER check pop
3800
3807
3801
- // TODO: detect overflow (FE_OVERFLOW), return +/- __builtin_inff()
3808
+ if (isinff (x_times_y ))
3809
+ {
3810
+ feraiseexcept (FE_OVERFLOW );
3811
+ return __CPROVER_signf (x_times_y ) ? - __builtin_inff () : __builtin_inff ();
3812
+ }
3802
3813
// TODO: detect underflow (FE_UNDERFLOW), return +/- 0
3814
+
3803
3815
return x_times_y + z ;
3804
3816
}
3805
3817
@@ -3839,6 +3851,7 @@ long double fmal(long double x, long double y, long double z)
3839
3851
else if (isnanl (z ))
3840
3852
return 0.0l / 0.0l ;
3841
3853
3854
+ #pragma CPROVER check disable "float-overflow"
3842
3855
long double x_times_y = x * y ;
3843
3856
if (
3844
3857
isinfl (x_times_y ) && isinfl (z ) &&
@@ -3852,8 +3865,13 @@ long double fmal(long double x, long double y, long double z)
3852
3865
#if LDBL_MAX_EXP == DBL_MAX_EXP
3853
3866
return fma (x , y , z );
3854
3867
#else
3855
- // TODO: detect overflow (FE_OVERFLOW), return +/- __builtin_infl()
3868
+ if (isinfl (x_times_y ))
3869
+ {
3870
+ feraiseexcept (FE_OVERFLOW );
3871
+ return __CPROVER_signld (x_times_y ) ? - __builtin_infl () : __builtin_infl ();
3872
+ }
3856
3873
// TODO: detect underflow (FE_UNDERFLOW), return +/- 0
3874
+
3857
3875
return x_times_y + z ;
3858
3876
#endif
3859
3877
}
0 commit comments