Floating point
scott andrew franco
samiam at moorecad.com
Tue Sep 1 05:26:43 CEST 2020
In any case, yes, I see the test does not work. Its 1735 (from the Pascal-P5 test catalog):
{
PRT test 1735: For trunc(x), the value of trunc(x) is such that if x is
positive or zero then 0 < x-trunc(x) < 1; otherwise 1 <x-
trunc(x) < 0. It is an error if such a value does not exist.
ISO 7185 reference: 6.6.5.3
}
program iso7185prt1735;
var a: integer;
b: real;
begin
{ assign maximum value of integer }
b := maxint;
{ now move it completely out of range in floating point only }
b := b+10.0;
{ now the assignment is invalid }
a := trunc(b)
end.
I'm open to suggestions. ISO 7185 does not have a "maxreal" or similar.
I guess b := maxint; b := b*2 would do it. I was trying for something more subtle
(which clearly didn't work).
Regards,
Scott Franco
--------- Original Message --------- Subject: RE: Floating point
From: "scott andrew franco" <samiam at moorecad.com>
Date: 8/31/20 8:06 pm
To: "Waldek Hebisch" <hebisch at math.uni.wroc.pl>, "gpc at gnu.de" <gpc at gnu.de>
Waldek,
Sure, 48 bits vs 64 bits. Why didn't it truncate the mantissa on conversion to float, ie, b := maxint?
I would have expected something like zeros on the right side.
Thanks,
Scott
--------- Original Message --------- Subject: Floating point
From: "Waldek Hebisch" <hebisch at math.uni.wroc.pl>
Date: 8/31/20 7:58 pm
To: "gpc at gnu.de" <gpc at gnu.de>
On Mon, Aug 31, 2020 at 01:07:42PM -0700, scott andrew franco wrote:
> samiam at samiam-home-pc:~/projects/pascal/pascal-p5$ cat test.pas
> program test(output);
> var b,c: real;
> begin
> b := maxint;
> c := 10.0;
> b := b+c;
> writeln(b:40:1);
> writeln(maxint:38);
> end.
> samiam at samiam-home-pc:~/projects/pascal/pascal-p5$ gpc -o test test.pas
> samiam at samiam-home-pc:~/projects/pascal/pascal-p5$ ./test
> 9223372036854775808.0
> 9223372036854775807
Note that floating point results are approximate and on
64-bit machines real accuracy is lower than integer
accuracy.
--
Waldek Hebisch
_______________________________________________
Gpc mailing list
Gpc at gnu.de
https://www.g-n-u.de/mailman/listinfo/gpc
_______________________________________________ Gpc mailing list Gpc at gnu.de https://www.g-n-u.de/mailman/listinfo/gpc
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.g-n-u.de/pipermail/gpc/attachments/20200831/4ea5dc04/attachment.htm>
More information about the Gpc
mailing list