Operating System - OpenVMS
1830508 Members
2489 Online
110006 Solutions
New Discussion

Re: Simple multiplication gives incorrect results

 
SOLVED
Go to solution
GaryM
New Member

Simple multiplication gives incorrect results

I have a dcl script that multiplies the number of freeblocks of a device by the block size (512) to give me approximate Megabytes, but it gives me an incorrect value.

Actual example:
FS = f$getdvi("DISK1","FREEBLOCKS")
MB = FS*512
display FS --> 4995264
display MB --> -1737392128
expecting MB to be 2557575168
4 REPLIES 4
Jess Goodman
Esteemed Contributor
Solution

Re: Simple multiplication gives incorrect results

DCL can only handle 31 bit signed arithmetic. If you overflow 2^31 you will get a negative number with no error message because bit #31 is set and that is interpreted as the sign bit. If you overflow 2^32 the answer will wrap back over 0. Note with the numbers you posted:

1737392128
+2557575168
-----------
4294967296 = hex 100000000 = 2^32
I have one, but it's personal.
Jess Goodman
Esteemed Contributor

Re: Simple multiplication gives incorrect results

I should have added that if you just want the number of free Megabytes on the disk then do a division intead of multiplying.
(When you multiplied by 512 you were calclating the number of free bytes, not megabytes.)

FS = f$getdvi("DISK1","FREEBLOCKS")
MB = FS/2048

1 Block = 512 Bytes = 0.5 KiloBytes
1 MegaByte = 1024 KiloBytes

And welcome to the IT resource center forums.
I have one, but it's personal.
Steven Schweda
Honored Contributor

Re: Simple multiplication gives incorrect results

> DCL can only handle 31 bit signed arithmetic.

That's normally called 32-bit signed
arithmetic. One of the 32 bits is a sign
bit.

I don't recall a comp.os.vms question this
year from anyone wondering why some simple
floating-point calculation wasn't exact. Is
this as close as we get for 2007?
GaryM
New Member

Re: Simple multiplication gives incorrect results

Thanks for the explanations. That did the trick.