Page 1 of 1

integer to float

Posted: Tue Nov 09, 2004 9:57 am
by newdep
Hello Lutz,

Its it possible to extend Newlisp with an option in + - / * ... to
return not only integers but also autodetect i.e. floats.. and round
in float format? Currently an extra function is needed that does a
pack/unpack for float.

An examples on how i thought it could be done for float is i.e. to
add an "f" at the end of float numbers. But ofcaurse more elegant would
be an autodetect... (btw i know mul, add... exist ;-)

; a float
>(- 1000.54f 100.31f )
900.23

; a float/double
>(+ 1000.123456789123456 1.1234567789123456)

Or if someting like this would work it would be nice too ->

(float (- 123.34 35.123))


Regards,
Norman.

Posted: Tue Nov 09, 2004 1:41 pm
by Lutz
Just do at the beginning or in init.lsp:

(constant '+ add)
(constant '- sub)
(constant '* mul)
(constant '/ div)

Now +,-,*,/ will work on floats and integers alike. This is also described in the manual in the 'Customization, localization and UTF-8' chapter.


Lutz