[fpc-pascal] testing if a float has a fractional part
Sven Barth
pascaldragon at googlemail.com
Tue May 15 14:16:36 CEST 2018
Bart <bartjunk64 at gmail.com> schrieb am Di., 15. Mai 2018, 13:22:
> On Sun, May 13, 2018 at 3:40 PM, Jonas Maebe <jonas at freepascal.org> wrote:
> > The only proper way is to use something like Math.SameValue(x, int(x)).
>
> B.t.w. the test suite for the new Int() function (win64)
> (
> https://svn.freepascal.org/cgi-bin/viewvc.cgi/trunk/tests/tbs/tb0644.pp?view=markup
> )
> uses
>
> 47 function SameValue(aGot, aExpected: Double): Boolean;
> 48 begin
> 49 if IsNan(aExpected) then
> 50 Result := IsNan(aGot)
> 51 else
> 52 Result := aGot = aExpected;
> 53 end;
>
But that test tests a specific functionality and even remarks that it will
only work on targets that have Double as default floating point type (e.g.
Win64 and non-x86 targets). That test would fail on targets that have the
Extended type or only Single.
Thus it is safer (and more portable) to use Math.SameValue().
Regards,
Sven
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20180515/06011c0e/attachment.html>
More information about the fpc-pascal
mailing list