(42S) Integer Quotient - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Software Libraries (/forum-10.html) +--- Forum: General Software Library (/forum-13.html) +--- Thread: (42S) Integer Quotient (/thread-9107.html) |
(42S) Integer Quotient - Gerald H - 09-19-2017 06:38 AM 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. { 29-Byte Prgm } RE: (42S) Integer Quotient - Werner - 09-19-2017 07:45 AM You always need an auxiliary variable. I use "." for that. This program will compute Quotient and Rest Code: Y := q.X + r RE: (42S) Integer Quotient - Gerald H - 09-19-2017 08:46 AM 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. RE: (42S) Integer Quotient - Werner - 09-19-2017 11:20 AM If all you want to do is IDIV5: Code: 01>LBL "5/" Cheers, Werner RE: (42S) Integer Quotient - Gerald H - 09-19-2017 12:09 PM 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. { 27-Byte 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. RE: (42S) Integer Quotient - grsbanks - 09-20-2017 10:17 AM (09-19-2017 06:38 AM)Gerald H Wrote: For large input, eg 888,888,888,888 the 42S snippet Have you tried 5 BASE÷ ? I don't have my HP-42S with me so can't test this. RE: (42S) Integer Quotient - Gerald H - 09-20-2017 12:08 PM (09-20-2017 10:17 AM)grsbanks Wrote:(09-19-2017 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. |