Re: Request: Integer Division
- Posted by mattlewis (admin) Jan 02, 2013
- 1344 views
So Eu tracks the declared type integer all thru the program, and then ignores it and converts to type atom (floating point), does the most costly math possible on it, then truncates it and re-typecasts it as integer?
Actually, there are (and have been for as long as I'm aware) 4 division opcodes:
- DIVIDE
- DIV2
- FLOOR_DIV
- FLOOR_DIV2
The DIV2 versions attempt to use bitwise optimizations. The FLOOR versions use C integer division if the divisor and dividend are euphoria integer values (we may not know until runtime). One potential difference with explicit integer division is how we would deal with fractional values.
I can think of two ways to deal with this:
- floor( a / b )
- floor( floor(a) / floor(b) )
The second option would be similar to what you'd get in, say, C, where you'd do casts to int instead of calling floor() in order to invoke integer division on FP values.
Matt