Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2013-02

Invalid floating point operation - roundto

3 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Unknown author

Hi, I've problem with roundto function (fpc 2.6.0).

s1,s2: extended;
 s1:=291.022;
 s2:=roundto(s1,-30);   //TRoundToRange = -37..37;

give me Invalid floating point operation.

I see that roundto goes to single instead of extended. But why ?

Thanks,
Tomek

Reply by email

Jonas Maebe
to Unknown author
Show quoted text 8 lines
s1,s2: extended; s1:=291.022; s2:=roundto(s1,-30); //TRoundToRange = -37..37; give me Invalid floating point operation. I see that roundto goes to single instead of extended. But why ?

Because overload selection is based on parameter matching from right to left, and -30 can be exactly represented using "single" and hence is converted to that type by the compiler when it has to turn it into a floating point constant.

Jonas

Reply by email

Unknown author
to Jonas Maebe

I don't Get It.
Right parameter is TRoundToRange not single,double or extended. In that case howto get roundto with extended precision ? function RoundTo(const AVAlue: Extended; const Digits: TRoundToRange): Extended;

2013/3/6 Jonas Maebe :

Show quoted text 17 lines
On 22 Feb 2013, at 13:30, wrote: s1,s2: extended; s1:=291.022; s2:=roundto(s1,-30); //TRoundToRange = -37..37; give me Invalid floating point operation. I see that roundto goes to single instead of extended. But why ? Because overload selection is based on parameter matching from right to left, and -30 can be exactly represented using "single" and hence is converted to that type by the compiler when it has to turn it into a floating point constant.

Reply by email