What is math:intdiv doing?

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

The code for intdiv from std/math.e

public function intdivX(object a, object b)	 
	return sign(a)*ceil(abs(a)/abs(b)) 
end function 

produces this result:

include std/math.e 
 
? intdiv(10,1)  --> 10 
? intdiv(10,2)  --> 5 
? intdiv(10,3)  --> 4  //  3*4 = 12 
? intdiv(10,4)  --> 3  //  4*3 = 12  
? intdiv(10,5)  --> 2 

I expected something more like:

public function IntDiv( object a, object b ) 
 return sign(a) * floor( abs(a)/abs(b) ) 
end function 
 
? IntDiv(10,1) --> 10 
? IntDiv(10,2) --> 5  
? IntDiv(10,3) --> 3  // 3*3 = 9 
? IntDiv(10,4) --> 2  // 4*2 = 8 
? IntDiv(10,5) --> 2 

_tom

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

Search



Quick Links

User menu

Not signed in.

Misc Menu