Automatic integer conversion with basic math operators

For the Compleat Fan
Locked
HPW
Posts: 1390
Joined: Thu Sep 26, 2002 9:15 am
Location: Germany
Contact:

Automatic integer conversion with basic math operators

Post by HPW »

I find it not very well documented (and also strange) that the basic math operators are different to other lisps.

Code: Select all

(+ 1.12 2.13)
3

(integer?(+ 1.12 2.13))
true

(add 1.12 2.13)
3.25
In alisp, corman lisp and lispworks they return a float when one operand is a float. I had some unexpected results on porting code to newlisp on this.

So in fact they are only type polymorph on input, not on output.
Hans-Peter

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

in newLISP the outcome of the arithmetik operation is defined by the operator rather than by the operand. +,/,*,/ will convert their arguments to integers, before the operator gets applied, same is true for add,sub,mul and div the other way around.

newLISP was made with embedded systems applications in mind, so this was the right way to go (to have two sets of operators for integers and floats). In many scripting environments it may be better to just redefine +,-,*,/ as floating point operators with 'constant'. I will look into the documentation to see if these issues can be made clearer.

Lutz

HPW
Posts: 1390
Joined: Thu Sep 26, 2002 9:15 am
Location: Germany
Contact:

Post by HPW »

So now I know that newlisp operators works that way, I only have to keep an eye on it, when porting code to choose the right replacement for the universal operators from the other Lisp.

Thanks for the info.

Can you explain a bit about embedded systems applications?

Could there be a version on Pocket PC2003 in the future?

Found this related link:
http://mifki.ru/pocketgcc/index.html
Hans-Peter

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

'embedded' applications means, applocations embedded into some microprocessor driven device: from toaster, to printer to cell phone to car etc.. It's really the biggest field today for software. Probably 95% of all computing power sits in some device, which is not your general purpose computer on the desk or in the server room, but a CPU controlling some other device.

In these applications there is always a lot of dealing with hardware directly, setting bits at certain memory locations or writing to device ports directly.

Most of the time these devices have no floating point support at all and there is heavy dealing with integers, memory addresses, bit masks etc. That is while you need a clear seperation between the integer and floating point domain.

Lutz

Locked