Page 1 of 1

minus zero

Posted: Wed Dec 17, 2003 2:47 pm
by nigelbrown
I've noticed that:
> (ceil 0.0001)
1
> (ceil -0.0001)
-0
> (setq minuszero (ceil -0.0001))
-0
> minuszero
-0
> (= 0 minuszero)
true

The maths I've tried minuszero with act as I'd expect
except perhaps
> (abs minuszero )
-0
>

and (format doesn't like minuszero viz.
> (format "%d" minuszero)

data type and format don't match in function format : minuszero

> minuszero
-0
> (format "%x" minuszero)

data type and format don't match in function format : minuszero

>


Nigel

Posted: Wed Dec 17, 2003 3:22 pm
by nigelbrown
Sorry, of course data type and format don't match,
minus zero is a float
newLISP v7.4.0 Copyright (c) 2003 Lutz Mueller. All rights reserved.

> (setq mz (ceil -0.001))
-0
> (format "%f" mz)
"-0.000000"
>

I guess it's just a little quirk of computer floating point.

Nigel

Posted: Wed Dec 17, 2003 3:37 pm
by Lutz
Yes, when newLISP displays floats it uses the '%g' format so:

(set 'x 0.000) => 0

x => 0

that makes you than think it is an integer, but it is still a float.

Lutz