From 201d38d6fe1a8be5aa5237807103f49b4c8cb53c Mon Sep 17 00:00:00 2001 From: florian Date: Fri, 25 Oct 2024 23:10:23 +0200 Subject: [PATCH] * fix fpc_frac_real to properly thrown an exception on +/-Inf/NaN --- rtl/inc/genmath.inc | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/rtl/inc/genmath.inc b/rtl/inc/genmath.inc index d4d41f722e..6637ded744 100644 --- a/rtl/inc/genmath.inc +++ b/rtl/inc/genmath.inc @@ -1757,15 +1757,24 @@ end; {$ifndef FPC_SYSTEM_HAS_FRAC} +{$push} +{ if we have to check manually fpu exceptions, then force the result assignment statement here to + throw one } +{$CHECKFPUEXCEPTIONS+} +{ turn off fastmath as it converts (d-d)/zero into 0 and thus not raising an exception } +{$OPTIMIZATION NOFASTMATH} function fpc_frac_real(d : ValReal) : ValReal;compilerproc; + const + zero: ValReal = 0.0; begin { Nan or +/-Inf } if (float64high(d) and $7ff00000)=$7ff00000 then { return NaN } - result := (d-d)/0.0 + result := zero/zero else result := d - Int(d); end; +{$pop} {$endif}