#Modula 2 bug
5 messages in this thread
I recently found a bug and a workaround for it, in the TDI Modula-2, release 3.
If A is declared LONGREAL, this will not compile: A:=A+1.0; However, this will:
B:=1.0; A:=A+B; where B is also LONGREAL. Note that a similar workaround is
needed for A:=A*2.0; , etc. Apparently constants are marked are REAL
compatible, but not LONGREAL compatible, unless it is a simple equate. Mike
70030,160
Mike, does a := a * LONGREAL(2.0); work? Actually I'm not sure that this
statement really makes sense….floating point arithmetic is so
weird…….Richie
Probably not. I tried A:=A+LONGREAL(1.0); , and that did not work. Strange
indeed. Mike
There are supposed to be too functions LONG() and SHORT() which would let you
convert between 32-bit Reals, and 64-bit reals. I haven't played around with
them yet, but a friend of mine did. He says that the LONG() function isn't
implemented yet, and using SHORT() crashes his program. Oh well…
– Steve –
Mike,
This is not strange. I think, the LONGREAL(1.0) will just take the REAL
constant 1.0 and prefix it with zero filled bytes to obtain a value, which
occupies the same number of bytes as a LONGREAL. The TYPE(..) function is not a
conversion, but simply interpreting the bit pattern as if it was of another
type.
E.g. INTEGER(0FFFFH) is -1, but CARDINAL(0FFFFH) is 65535.
Joergen