🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

2 total messages Started by Peter Guttorp Wed, 18 Jul 1984 05:48
Integer data in S
#34
Author: Peter Guttorp
Date: Wed, 18 Jul 1984 05:48
15 lines
1086 bytes
One needs to be careful when reading in data without decimal points to S.
For example,
	1833008*2154246/2172348
evaluates to
	771.15
whereas
	1833008/2172348*2154246
evaluates (as was intended) to
	1817734

Apparently multiplication of integers is done mod 2^32, whereas on division
integers are changed to reals (of course, there is a separate integer
divide if one wants to actually do that). I find this feature a bit
disturbing, as I often work with data that are recorded in integer format,
but really will be treated as real. 
Re: Integer data in S
#35
Author: Rick Becker
Date: Fri, 13 Jul 1984 11:47
31 lines
1763 bytes
> One needs to be careful when reading in data without decimal points to S.
> For example,
> 	1833008*2154246/2172348
> evaluates to
> 	771.15
> whereas
> 	1833008/2172348*2154246
> evaluates (as was intended) to
> 	1817734
> 
> Apparently multiplication of integers is done mod 2^32, whereas on division
> integers are changed to reals (of course, there is a separate integer
> divide if one wants to actually do that). I find this feature a bit
> disturbing, as I often work with data that are recorded in integer format,
> but really will be treated as real. 
> 

With real arithmetic, the operating system generates a floating
exception for overflow, and S generates an error message.
In integer arithmetic, no exception occurs, so it is hard for S to detect
the problem.

As you noted, division actually forces a real result, to
produce the expected 1.5 from 3/2.  The real arithmetic won't overflow
on numbers as small as what you have, but integer arithmetic will.
The advantage of integer arithmetic is that it keeps more digits of
precision (31 bits plus sign vs. 23 bits using real arithmetic), hence
integer operations are occasionally useful.
-- 

    Rick Becker  rabbit!rab
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads