1. What is math:intdiv doing?

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 message » categorize

2. Re: What is math:intdiv doing?

_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

new topic     » goto parent     » topic index » view message » categorize

3. Re: What is math:intdiv doing?

Lnettnay said...

Hope this helps,

Lonny

Yes it helps, very much. I googled for "integral division" without a hit other than calculus.

The intdiv function seems to be poorly named and docs don't help much.

If this function looked like:

packages = packing( items, groups ) 

it makes more sense.

thanks

_tom

new topic     » goto parent     » topic index » view message » categorize

4. Re: What is math:intdiv doing?

_tom said...

The intdiv function seems to be poorly named and docs don't help much.

Maybe you meant "The intdiv function seems to be terribly named..."?

new topic     » goto parent     » topic index » view message » categorize

5. Re: What is math:intdiv doing?

Thanks Lonny and Shian,

I found a solution to "intdev" which I now call intact division.

_tom


intdiv

include intdiv.ex 
public function intdiv(object dividend, object divisor) 

returns an intact division of two objects.

Arguments:
  1. dividend : any Euphoria object.
  2. divisor : any Euphoria object.
Returns:

An object, which will be a sequence if either dividend or divisor is a sequence.

Comments:

Starting with a number of items, how many containers are needed when each container has a fixed maximum size? Since you can not have a fractional container you must perform what we will call an intact division. Every container will be full of items except that the last container could be partially full--every container remains intact.

  • The dividend is the number of items to be packed.
  • The divisor is the size of the container.
  • The return is the number of intact containers.
Example 1:
include std/math.e 
 
atom tokens = 101 
atom perEnvelope = 5 
 
? 101/5 
--> 20.2  -- but, can not have 0.2 envelopes 
 
integer envelopes = intdiv( tokens, perEnvelope ) 
? envelopes 
--> 21 
new topic     » goto parent     » topic index » view message » categorize

6. Re: What is math:intdiv doing?

_tom said...

Thanks Lonny and Shian,

I found a solution to "intdev" which I now call intact division.

_tom

Brilliant!

new topic     » goto parent     » topic index » view message » categorize

7. Re: What is math:intdiv doing?

Relief.

I was afraid to ask about it...

BTW in the math.e section of the manual I found some other mistakes(?), I don't remember now and I don't have Euphoria next to me, but as far as I remember it was mistakes in Examples which display a comma ',' instead of period '.', such as (from the manual):

? arcsinh(1) -- prints out 0,4812118250596034
? arctanh(1/2) -- prints out 0,5493061443340548456976

If it's truly wrong then I guess that it should be fixed.

new topic     » goto parent     » topic index » view message » categorize

8. Re: What is math:intdiv doing?

Shian_Lee said...

Relief.

I was afraid to ask about it...

BTW in the math.e section of the manual I found some other mistakes(?), I don't remember now and I don't have Euphoria next to me, but as far as I remember it was mistakes in Examples which display a comma ',' instead of period '.', such as (from the manual):

? arcsinh(1) -- prints out 0,4812118250596034
? arctanh(1/2) -- prints out 0,5493061443340548456976

If it's truly wrong then I guess that it should be fixed.

You are right. The examples should not have a comma. Not only that one value is wrong:

include std/math.e 
? arcsinh( 1 ) 
? arctanh( 1/2 ) 

produces:

0.881373587 
0.5493061443 

Thanks,

_tom

new topic     » goto parent     » topic index » view message » categorize

9. Re: What is math:intdiv doing?

Why do you English speaking people think YOU are correct about the decimal point?
ALL others nations use a comma to seperate whole numbers from the decimals and a period
to distinguish between powers of 1000.
AND they outnumber you by 5 against 2! or even more

new topic     » goto parent     » topic index » view message » categorize

10. Re: What is math:intdiv doing?

Ekhnat0n said...

ALL others nations use a comma to seperate whole numbers from the decimals and a period
to distinguish between powers of 1000.

That's not how it's done in China.

new topic     » goto parent     » topic index » view message » categorize

11. Re: What is math:intdiv doing?

jimcbrown said...
Ekhnat0n said...

ALL others nations use a comma to seperate whole numbers from the decimals and a period
to distinguish between powers of 1000.

That's not how it's done in China.



Though you are right about the current way they write numbers in China,
this is only because they adapted to the 'leading nation's' way of writing them down
to avoid any ambiguity about HOW MUCH of USA's national debt is owed to them ;)

new topic     » goto parent     » topic index » view message » categorize

12. Re: What is math:intdiv doing?

Ekhnat0n said...

Though you are right about the current way they write numbers in China,
this is only because they adapted to the 'leading nation's' way of writing them down
to avoid any ambiguity about HOW MUCH of USA's national debt is owed to them ;)

Chinese mentality never did or will adapt itself to other's.

Currently China is the leading nation de-facto. Soon, both comma & period will be considered as a crime - as well as talking English in public.

So let's enjoy both commas & periods as long as it's still legal.

History will prove that it's true.

new topic     » goto parent     » topic index » view message » categorize

13. Re: What is math:intdiv doing?

Shian_Lee said...

Chinese mentality never did or will adapt itself to other's.

Currently China is the leading nation de-facto. Soon, both comma & period will be considered as a crime - as well as talking English in public.

So let's enjoy both commas & periods as long as it's still legal.

History will prove that it's true.

Of course China never adapts AND they are right not doing so, Shian_Lee.
Simply because there is so much western countries can learn from an ancient
civilisation like theirs (eg medical knowledge but also the way to behave).
Also your native country indeed is the de-facto leading nation nowadays.

I never would deny that, although 'us Dutch people' go a long way too and have (&have had) many leading
scientists among us, due to the liberal approach in the 16th/17th century by providing asylum
to those who were prosecuted in their own countries.
Most of us have profited from that and in our veins runs the blood of men like Boerhaave, Erasmus, C.Huygens
and lots more.

We have been front-runners in many fields until regrettably our government started
to function as a dragging anchor, preventing those among us, who are ahead of our time,
to fully deploy their strength.

new topic     » goto parent     » topic index » view message » categorize

14. Re: What is math:intdiv doing?

From my point of view, Dutch people won the ocean, Ekhnat0n.
That is more then enough to prove their courage, faith and wisdom.

new topic     » goto parent     » topic index » view message » categorize

15. Re: What is math:intdiv doing?

Ekhnat0n said...



Though you are right about the current way they write numbers in China,
this is only because they adapted to the 'leading nation's' way of writing them down

Actually, the way it was done originally was with no punctuation at all. No arabic numerals either.

new topic     » goto parent     » topic index » view message » categorize

16. Re: What is math:intdiv doing?

jimcbrown said...
Ekhnat0n said...



Though you are right about the current way they write numbers in China,
this is only because they adapted to the 'leading nation's' way of writing them down

Actually, the way it was done originally was with no punctuation at all. No arabic numerals either.

I guess that what Ekhnat0n said between the lines is: 'Don't include China in this "game"'.

I must agree with this. China has in and out. I would not be surprised if China will turn its back to America in a single moment, and disallow teaching western culture on their land, including using western symbols. This is more then realistic option.

new topic     » goto parent     » topic index » view message » categorize

17. Re: What is math:intdiv doing?

Shian_Lee said...

I guess that what Ekhnat0n said between the lines is: 'Don't include China in this "game"'.
I must agree with this. China has in and out. I would not be surprised if China will turn its back to America in a single moment, and disallow teaching western culture on their land, including using western symbols. This is more then realistic option.



DRUMROLL for Shian_Lee.
You got my drift my friend although you forgot to mention that we not only won the ocean,
how small we were as a country but we won an 80-years war (1568-1648) against the united forces of
France, Spain, Germany and the United Kingdom and were welcome visitors to both China and Japan
in those days too.

Alas I have to admit that we were the last country in the world to abolish slavery as well.

Way off topic ofc. for the TS smile

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu