integer functions on floats

Started by Dmi, March 30, 2006, 09:53:13 AM

Previous topic - Next topic

Dmi

Lutz, I just got an idea:


(+ 1.5 2.3) => 3

In my own practice, this implicit conversion from a float to an integer in functions, such as (+) and (-) mostly causes a mistakes and is really useful in rare cases.



Probably, it will be good - to supress the conversion (throw a type error) and force programmer convert it explicitly?
WBR, Dmi

Lutz

#1
I know some using this. Those who don;t like it should put:

(constant (global '+) add)
   ...

in there init.lsp or ~/.init.lsp

> (constant (global '+) add)

> (+ 1.2 3.4)
4.6
>



Then there will be always implicit conversion to float only like in Perl/Python etc., and only when writing library interfaces the (int ...) cast is used. I believe throwing errors will confuse more as all other functions also convert from/to int/float as needed.



Lutz

Dmi

#2
Thanx for a trick - now my financial calculations will lose the cents less frequently :-)



Simply I've think about absence of such autoconversion for strings and got an idea, that the integers relyes to the floats like to the strings...

Just an idea... :-)
WBR, Dmi