(42S) Integer Quotient

09192017, 06:38 AM
Post: #1




(42S) Integer Quotient
For large input, eg 888,888,888,888 the 42S snippet
5 / IP does not return the correct integer quotient. I have a programme to do the calculation correctly without disturbing the stack but believe it is inefficient. Could someone suggest a more efficient programme that leaves the stack intact? Code: 0. { 29Byte Prgm } 

09192017, 07:45 AM
Post: #2




RE: (42S) Integer Quotient
You always need an auxiliary variable. I use "." for that.
This program will compute Quotient and Rest Code: Y := q.X + r 

09192017, 08:46 AM
Post: #3




RE: (42S) Integer Quotient
Thank you, Werner, I shall certainly use your programme when I need IDIV2.
For my current problem I guess it's necessary to calculate modulo off the stack using register arithmetic, but that appears to be too complicated to be efficient, or at any rate more efficient than my programme above. 

09192017, 11:20 AM
Post: #4




RE: (42S) Integer Quotient
If all you want to do is IDIV5:
Code: 01>LBL "5/" Cheers, Werner 

09192017, 12:09 PM
Post: #5




RE: (42S) Integer Quotient
Beautiful, Werner, I love you.
Which leads to my programme which does what I want. Store 10 in variable "10" & the following programme finds integer quotient on division by 5 without disturbing the stack: Code: 0. { 27Byte Prgm } The question now is which is faster, my programme in the initial posting or this one  in terms of elegance this one wins hands down. 

09202017, 10:17 AM
Post: #6




RE: (42S) Integer Quotient  
09202017, 12:08 PM
Post: #7




RE: (42S) Integer Quotient
(09202017 10:17 AM)grsbanks Wrote:(09192017 06:38 AM)Gerald H Wrote: For large input, eg 888,888,888,888 the 42S snippet Yes, that's the right idea, but doesn't work for large numbers. 

« Next Oldest  Next Newest »

User(s) browsing this thread: 1 Guest(s)