Re: Request: Integer Division

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

This really should be in a Request-for-Feature ticket, but...

SnakeCharmer said...

I offer to include integer division, for example:

integer Y = 3
integer Z = 2 
integer X = Y \ Z

instead of

integer X = trunc(X/Z)

because it is more effective. First option is equivalent for

integer X = 0
while Y >= Z do 
X += 1 
Y -= Z 
end while

Second option is equivalent for

integer Y = 3
integer Z = 2 
atom YY = Y 
atom ZZ = Z 
atom XX = YY / ZZ 
integer X = trunc(XX)

As far as I know, integer addition and subtraction is much more effective than the division of floating point numbers.

I think the syntax is the most contriversal part here.

Adding a new builtin or machine func, like so:

integer X = integer_division(Y,Z) 

which is equivalent to

integer X = 0 
while Y >= Z do 
X += 1 
Y -= Z 
end while 

but implemented using integer division at the assembler level is pretty easy to do, and it's certainly a lot faster and more efficient than using intdiv.

I think however, changing the syntax such that

integer X = Y \ Z 

does integer division, may break backwards compatibility and could be confusing, considering the way that the current and older versions of Euphoria handled this.

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

Search



Quick Links

User menu

Not signed in.

Misc Menu