minus zero

Started by nigelbrown, December 17, 2003, 06:47:18 AM

Previous topic - Next topic

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

nigelbrown

#1
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

Lutz

#2
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