Re: Request: Integer Division

new topic     » goto parent     » topic index » view thread      » older message » newer message
useless_ said...

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:

  1. floor( a / b )
  2. 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

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu