rab@rabbit.UUCP (Rick Becker) (07/13/84)
> 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
peter@entropy.UUCP (Peter Guttorp) (07/18/84)
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.