Hi all,
i'm movig my first step with newLISP and Lisp in general,
I'm just curious about the +,-,*,/, ecc...
why they return only integer number?
About math operators
The operators +,-,*,/ do only integer (64 bit) arithmetic.
Use add,sub,mul,div for float (IEE 754 double float) and mixed arithmetic.
You can make +,-,*,/ act like add.sub,mul,div doing:
but you will lose the precision of 64 bit integers. Most newLISP users rapidly get accustomed using both +,-,*,/ and add,sub,mul,div.
See also here: http://newlisp.org/newlisp_manual.html#int_float
Lutz
Use add,sub,mul,div for float (IEE 754 double float) and mixed arithmetic.
You can make +,-,*,/ act like add.sub,mul,div doing:
Code: Select all
(constant '+ add)
(constant '- sub)
(constant '* mul)
(constant '/ div)
See also here: http://newlisp.org/newlisp_manual.html#int_float
Lutz
it would give you back an integer but everything coming out of floating point has only about 15 digits of precision, while with int yuu get to about 18 digit. Casting to an int doesn't give you back precision and will cut off all decimals.cavva wrote:(int (add 1 1.5 2))
Also: all functions in newLISP "know" if they need an integer or float and will automatically convert, so casting normally is only necessary when calling routines imported from C libraries.
Lutz
-
- Posts: 2038
- Joined: Tue Nov 29, 2005 8:28 pm
- Location: latiitude 50N longitude 3W
- Contact:
I've written a little about working with numbers, and some of the things to be aware of. I hope it might be of some help:
http://newlisp.org/introduction-to-newl ... ithnumbers
http://newlisp.org/introduction-to-newl ... ithnumbers
@Lutz
didn't know about the difference in the digit precision,
i think i must get some acknowledgement.
What about this?
@cormullion
Thanks, your document was my starting point, but i don't read well the chapter 9 :)
thanks Lutz,Lutz wrote: it would give you back an integer but everything coming out of floating point has only about 15 digits of precision, while with int yuu get to about 18 digit. Casting to an int doesn't give you back precision and will cut off all decimals.
didn't know about the difference in the digit precision,
i think i must get some acknowledgement.
What about this?
is something simple as "call" 'integer? or 'float? on the function arguments or something else?
Also: all functions in newLISP "know" if they need an integer or float and will automatically convert, so casting normally is only necessary when calling routines imported from C libraries.
@cormullion
Thanks, your document was my starting point, but i don't read well the chapter 9 :)