RE: Floating point
"scott andrew franco" <[email protected]> Mon, 31 Aug 2020 20:26:43 -0700
| Newsgroups | gmane.comp.compilers.gpc |
|---|---|
| Message-ID | <20200831202643.6c61c97e98fe7bb02193b2d6dca4a85a.b294646839.mailapi@email15.godaddy.com> |
--===============0427392043136300721==
Content-Type: multipart/alternative;
boundary="=_f74c3a8229c57f62b03381893d9b841e"
--=_f74c3a8229c57f62b03381893d9b841e
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;
charset=utf-8
In any case, yes, I see the test does not work. Its 1735 (from the Pascal-P=
5 test catalog):
=20
{
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 :=3D maxint;
{ now move it completely out of range in floating point only }
b :=3D b+10.0;
{ now the assignment is invalid }
a :=3D trunc(b)
end.
I'm open to suggestions. ISO 7185 does not have a "maxreal" or similar.
I guess b :=3D maxint; b :=3D b*2 would do it. I was trying for something =
more subtle
(which clearly didn't work).
Regards,
Scott Franco
=20
--------- Original Message --------- Subject: RE: Floating point
From: "scott andrew franco" <[email protected]>
Date: 8/31/20 8:06 pm
To: "Waldek Hebisch" <[email protected]>, "[email protected]" <[email protected]>
Waldek,
=20
Sure, 48 bits vs 64 bits. Why didn't it truncate the mantissa on conversion=
to float, ie, b :=3D maxint?
I would have expected something like zeros on the right side.
=20
Thanks,
=20
Scott
=20
--------- Original Message --------- Subject: Floating point
From: "Waldek Hebisch" <[email protected]>
Date: 8/31/20 7:58 pm
To: "[email protected]" <[email protected]>
On Mon, Aug 31, 2020 at 01:07:42PM -0700, scott andrew franco wrote:
> samiam@samiam-home-pc:~/projects/pascal/pascal-p5$ cat test.pas
> program test(output);
> var b,c: real;
> begin
> b :=3D maxint;
> c :=3D 10.0;
> b :=3D b+c;
> writeln(b:40:1);
> writeln(maxint:38);
> end.
> samiam@samiam-home-pc:~/projects/pascal/pascal-p5$ gpc -o test test.pas
> samiam@samiam-home-pc:~/projects/pascal/pascal-p5$ ./test
> 9223372036854775808.0
> 9223372036854775807
=20
Note that floating point results are approximate and on
64-bit machines real accuracy is lower than integer
accuracy.
=20
--=20
Waldek Hebisch
=20
_______________________________________________
Gpc mailing list
[email protected]
https://www.g-n-u.de/mailman/listinfo/gpc
_______________________________________________ Gpc mailing list Gpc@gnu=
=2Ede https://www.g-n-u.de/mailman/listinfo/gpc
--=_f74c3a8229c57f62b03381893d9b841e
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html;
charset=utf-8
<div>In any case, yes, I see the test does not work. Its 1735 (from the Pas=
cal-P5 test catalog):</div>
<div> </div>
<div>{</div>
<div>
<p>PRT test 1735: For trunc(x), the value of trunc(x) is such that if x is<=
br /> positive or zero then 0 < x-trunc(x) < 1; otherwise 1 <x-<br=
/> trunc(x) < 0. It is an error if such a value does not exist.</p>
<p>ISO 7185 reference: 6.6.5.3</p>
<p>}</p>
<p>program iso7185prt1735;</p>
<p>var a: integer;<br /> b: real;</p>
<p>begin</p>
<p>{ assign maximum value of integer }<br /> b :=3D maxint;<br /> { now mov=
e it completely out of range in floating point only }<br /> b :=3D b+10.0;<=
br /> { now the assignment is invalid }<br /> a :=3D trunc(b)</p>
<p>end.</p>
<p>I'm open to suggestions. ISO 7185 does not have a "maxreal" or similar=
=2E</p>
<p>I guess b :=3D maxint; b :=3D b*2 would do it. I was trying for somethin=
g more subtle</p>
<p>(which clearly didn't work).</p>
<p>Regards,</p>
<p>Scott Franco</p>
</div>
<blockquote class=3D"threadBlockQuote" style=3D"border-left: 2px solid #C2C=
2C2; padding-left: 3px; margin-left: 4px;">--------- Original Message -----=
----
<div>Subject: RE: Floating point<br />From: "scott andrew franco" <samia=
[email protected]><br />Date: 8/31/20 8:06 pm<br />To: "Waldek Hebisch" <=
;[email protected]>, "[email protected]" <[email protected]><br /><br />
<div>Waldek,</div>
<div> </div>
<div>Sure, 48 bits vs 64 bits. Why didn't it truncate the mantissa on =
conversion to float, ie, b :=3D maxint?</div>
<div>I would have expected something like zeros on the right side.</div>
<div> </div>
<div>Thanks,</div>
<div> </div>
<div>Scott</div>
<div> </div>
<blockquote class=3D"threadBlockQuote" style=3D"border-left: 2px solid #C2C=
2C2; padding-left: 3px; margin-left: 4px;">--------- Original Message -----=
----
<div>Subject: Floating point<br />From: "Waldek Hebisch" <hebisch@math=
=2Euni.wroc.pl><br />Date: 8/31/20 7:58 pm<br />To: "[email protected]" <gpc=
@gnu.de><br /><br />On Mon, Aug 31, 2020 at 01:07:42PM -0700, scott andr=
ew franco wrote:<br /> > samiam@samiam-home-pc:~/projects/pascal/pascal-=
p5$ cat test.pas<br /> > program test(output);<br /> > var b,c: real;=
<br /> > begin<br /> > b :=3D maxint;<br /> > c :=3D 10.0;<br /> &=
gt; b :=3D b+c;<br /> > writeln(b:40:1);<br /> > writeln(maxint:38);<=
br /> > end.<br /> > samiam@samiam-home-pc:~/projects/pascal/pascal-p=
5$ gpc -o test test.pas<br /> > samiam@samiam-home-pc:~/projects/pascal/=
pascal-p5$ ./test<br /> > 9223372036854775808.0<br /> > 9223372036854=
775807<br /> <br /> Note that floating point results are approximate and on=
<br /> 64-bit machines real accuracy is lower than integer<br /> accuracy=
=2E<br /> <br /> -- <br /> Waldek Hebisch<br /> <br /> ____________________=
___________________________<br /> Gpc mailing list<br /> [email protected]<br /> h=
ttps://www.g-n-u.de/mailman/listinfo/gpc</div>
</blockquote>
_______________________________________________ Gpc mailing list [email protected]=
https://www.g-n-u.de/mailman/listinfo/gpc</div>
</blockquote>
--=_f74c3a8229c57f62b03381893d9b841e--
--===============0427392043136300721==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
Gpc mailing list
[email protected]
https://www.g-n-u.de/mailman/listinfo/gpc
--===============0427392043136300721==--