@@ -3736,6 +3736,7 @@ double fma(double x, double y, double z)
3736
3736
else if (isnan (z ))
3737
3737
return 0.0 / 0.0 ;
3738
3738
3739
+ #pragma CPROVER check disable "float-overflow"
3739
3740
double x_times_y = x * y ;
3740
3741
if (
3741
3742
isinf (x_times_y ) && isinf (z ) &&
@@ -3746,8 +3747,13 @@ double fma(double x, double y, double z)
3746
3747
}
3747
3748
#pragma CPROVER check pop
3748
3749
3749
- // TODO: detect overflow (FE_OVERFLOW), return +/- __builtin_inf()
3750
+ if (isinf (x_times_y ))
3751
+ {
3752
+ feraiseexcept (FE_OVERFLOW );
3753
+ return __CPROVER_signd (x_times_y ) ? - __builtin_inf () : __builtin_inf ();
3754
+ }
3750
3755
// TODO: detect underflow (FE_UNDERFLOW), return +/- 0
3756
+
3751
3757
return x_times_y + z ;
3752
3758
}
3753
3759
@@ -3782,6 +3788,7 @@ float fmaf(float x, float y, float z)
3782
3788
else if (isnanf (z ))
3783
3789
return 0.0f / 0.0f ;
3784
3790
3791
+ #pragma CPROVER check disable "float-overflow"
3785
3792
float x_times_y = x * y ;
3786
3793
if (
3787
3794
isinff (x_times_y ) && isinff (z ) &&
@@ -3792,8 +3799,13 @@ float fmaf(float x, float y, float z)
3792
3799
}
3793
3800
#pragma CPROVER check pop
3794
3801
3795
- // TODO: detect overflow (FE_OVERFLOW), return +/- __builtin_inff()
3802
+ if (isinff (x_times_y ))
3803
+ {
3804
+ feraiseexcept (FE_OVERFLOW );
3805
+ return __CPROVER_signf (x_times_y ) ? - __builtin_inff () : __builtin_inff ();
3806
+ }
3796
3807
// TODO: detect underflow (FE_UNDERFLOW), return +/- 0
3808
+
3797
3809
return x_times_y + z ;
3798
3810
}
3799
3811
@@ -3833,6 +3845,7 @@ long double fmal(long double x, long double y, long double z)
3833
3845
else if (isnanl (z ))
3834
3846
return 0.0l / 0.0l ;
3835
3847
3848
+ #pragma CPROVER check disable "float-overflow"
3836
3849
long double x_times_y = x * y ;
3837
3850
if (
3838
3851
isinfl (x_times_y ) && isinfl (z ) &&
@@ -3846,8 +3859,13 @@ long double fmal(long double x, long double y, long double z)
3846
3859
#if LDBL_MAX_EXP == DBL_MAX_EXP
3847
3860
return fma (x , y , z );
3848
3861
#else
3849
- // TODO: detect overflow (FE_OVERFLOW), return +/- __builtin_infl()
3862
+ if (isinfl (x_times_y ))
3863
+ {
3864
+ feraiseexcept (FE_OVERFLOW );
3865
+ return __CPROVER_signld (x_times_y ) ? - __builtin_infl () : __builtin_infl ();
3866
+ }
3850
3867
// TODO: detect underflow (FE_UNDERFLOW), return +/- 0
3868
+
3851
3869
return x_times_y + z ;
3852
3870
#endif
3853
3871
}
0 commit comments