Jump to content
jptf59

System.pas floating point error with Delphi10.3.3 RIO

Recommended Posts

Hello,

 

Code that worked fine with DELPHI 7 now generates a floating point error in System.Pas provided with the RadStudio 10.3.3 installer.  I use the Win32 platform.

My code is as following  and the problem lies with the round () instruction:

 

  if ( abs(extr.X-centre.X)  < 19) and (abs(extr.Y-centre.Y) < 19) then
     begin
       if (angl >= 45) and (angl < 135) then dl := abs(20/cos(DEC_RAD (90-angl)))
       else
       if  (angl >= 135) and (angl < 225) then dl := abs(20/cos(DEC_RAD (180-angl)))
       else
       if  (angl >= 225) and (angl < 315) then dl := abs(20/cos(DEC_RAD (270-angl)))
       else dl := abs(20/cos(DEC_RAD (-angl)));

       extr.X := org.X + round ( (long - dl) *cos (DEC_RAD(angl)));
       extr.Y := org.Y - round ( (long - dl) * sin (DEC_RAD (angl)));
     end;

The error occurs at the last line with the call to   round (( long - dl)  which calls in turn System._Round that is the intrinsec function compliant with dcc32 here :

{**************************************************}
{                                                  }
{           CodeGear Delphi Runtime Library        }
{                                                      			  }
{ Copyright(c) 1995-2019 Embarcadero Technologies, Inc. 	  }
{              All rights reserved                      			  }
{                                                       			  }
{   Copyright and license exceptions noted in source    		  }
{                                                       			  }
{**************************************************}

unit System; { Predefined constants, types, procedures, }
             { and functions (such as True, Integer, or }
             { Writeln) do not have actual declarations.}
             { Instead they are built into the compiler }
             { and are treated as if they were declared }
             { at the beginning of the System unit.     }
..............
 ----------------------------------------------------- }
{       functions & procedures that need compiler magic }
{ ----------------------------------------------------- }

{$IF defined(CPUX64) and defined(ASSEMBLER)}
function _Round(Val: Extended): Int64;
asm
        .NOFRAME
        CVTSD2SI        RAX, XMM0
end;
{$ELSEIF defined(X86ASMRTL)}
procedure _ROUND;
asm
        { ->    FST(0)  Extended argument       }
        { <-    EDX:EAX Result                  }

        SUB     ESP,12
{$IFDEF IOS} // iOS/Simulator
        CALL    FClearExcept
{$ENDIF IOS}
        FISTP   qword ptr [ESP+4]
        FWAIT
{$IFDEF IOS} // iOS/Simulator
        CALL    FCheckExcept
{$ENDIF IOS}

I get the $C0000090 'floating point invalid operation at 0x00407847' that points to the FWAIT instruction at the end of the _ROUND proc. 

 

What is strange is that the first call to round (long - dl)  does not generate any error  !   I read in the comment here above that the ROUND procedure needs compiler magic.  I do not know what it is and I cannot find it in the compiler options.  What is compiler magic ?

 

And all that works fine with Delphi 7. 

Thank you in advance for your help if you can.

Regards

JP

 

Edited by jptf59

Share this post


Link to post

This should be simple to resolve. Create a minimal program, including any input, so we can see what combination of rounding mode and input arguments lead to this exception. 

Share this post


Link to post

Thank you for your help that was good sense.  I discovered that the issue lies in my input data that was empty at times and not in System.pas !  

Problem solved !

 

Thank you again

 

JP

  • Like 1

Share this post


Link to post
Guest

for that is always recomended "initialize" your vars/objects to avoid randomic and strangers values for consequence!

Share this post


Link to post
2 hours ago, jptf59 said:

Thank you for your help that was good sense.  I discovered that the issue lies in my input data that was empty at times and not in System.pas !  

Problem solved !

 

Thank you again

 

JP

Floating point values cannot be empty

Share this post


Link to post

Um, the basic rule: always check the input arguments!
This is from a wise book :classic_smile:

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×