(41C) Quotient and Remainder
|
04-05-2023, 09:12 AM
(This post was last modified: 04-06-2023 05:40 AM by Werner.)
Post: #1
|
|||
|
|||
(41C) Quotient and Remainder
[Update: for now, only for positive X and Y]
You would think this is a no-brainer, but, as has been touched upon a couple of times, you can't just calculate the Quotient with INT(Y/X), as that will fail when rounding occurs in the division. The following routine gets it right, and even saves X in LASTX: Code: @ given X and Y, determine Quotient=DIV(Y,X) and Remainder=MOD(Y,X) Try for instance: Y: 4 000 000 001, 4 000 000 002, 4 000 000 003 X: 4 and get the correct Q: 1E9 R: 1,2,3 or Y: 2.000000003E19 X: 4E9 to get Q: 5 000 000 007 R: 2 000 000 000 Getting it right on machines that do round-to-even is somewhat harder. Stay tuned for my 42S solution, in another section of this forum. Cheers, Werner as an afterthought: this RQ split will only work when it makes sense, eg not for Y=1e40 and X=6 because then Q carries too many digits 41CV†,42S,48GX,49G,DM42,DM41X,17BII,15CE,DM15L,12C,16CE |
|||
« Next Oldest | Next Newest »
|
Messages In This Thread |
(41C) Quotient and Remainder - Werner - 04-05-2023 09:12 AM
RE: (41C) Quotient and Remainder - Joe Horn - 04-05-2023, 12:25 PM
RE: (41C) Quotient and Remainder - Werner - 04-05-2023, 01:08 PM
RE: (41C) Quotient and Remainder - Ángel Martin - 04-05-2023, 02:44 PM
RE: (41C) Quotient and Remainder - Werner - 04-10-2023, 07:25 AM
RE: (41C) Quotient and Remainder - Ángel Martin - 04-16-2023, 03:32 PM
RE: (41C) Quotient and Remainder - J-F Garnier - 04-16-2023, 06:30 PM
RE: (41C) Quotient and Remainder - Ángel Martin - 04-18-2023, 05:40 AM
RE: (41C) Quotient and Remainder - J-F Garnier - 04-18-2023, 10:24 AM
RE: (41C) Quotient and Remainder - Werner - 04-18-2023, 02:57 PM
RE: (41C) Quotient and Remainder - J-F Garnier - 04-18-2023, 03:13 PM
RE: (41C) Quotient and Remainder - Ángel Martin - 04-19-2023, 06:41 AM
|
User(s) browsing this thread: 1 Guest(s)