Re: What is math:intdiv doing?
- Posted by Lnettnay Mar 30, 2015
- 1804 views
_tom said...
The code for intdiv from std/math.e
public function intdiv(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
_tom
Hi _tom,
From the docs it appears that the purpose of intdiv is to give the minimum number of containers that will be needed for a certain number of items. If I have 10 items and can only fit 3 or 4 per container then I will need 4 containers.
8.24.2.5 intdiv
include std/math.e namespace math public function intdiv(object a, object b) -- might have been more clear if the signature was -- public function intdiv(object dividend, object divisor)
Return an integral division of two objects. Parameters: dividend : any Euphoria object. divisor : any Euphoria object. Returns: An object, which will be a sequence if either dividend or divisor is a sequence. Comments: This calculates how many non-empty sets when dividend is divided by divisor. The result's sign is the same as the dividend's sign.Example 1:
object Tokens = 101 object MaxPerEnvelope = 5 integer Envelopes = intdiv( Tokens, MaxPerEnvelope) --> 21
Hope this helps,
Lonny