(42S) Quotient and Remainder

04052023, 12:39 PM
Post: #2




RE: (42S) Quotient and Remainder
Hi, Werner
It had been 2 years. I provided 2 versions for floordivide #1: we assumed "normal" division was roundtonearest, halfwaytoeven. The trick is to reverse engineer how it was done, and reverse the "damage". (12202020 03:22 AM)Albert Chan Wrote: To handle signs of a, b, correction test: remainder(a,b)/b < 0 and q1 or q #2: more direct way, based from FMA(q, b, a) = q*b + a Fixing q (for floordivide) is similar: FMA(q, b, a)/b < 0 and q1 or q The downside is that 42S does not have FMA (almost no calculator does ...) Free42/Plus42 only had it recently (Free42 version ≥ 2.5.23, all Plus42 versions) (01082021 05:24 PM)Albert Chan Wrote: FMA based DIV behave the same as my REM based DIV. Click on the green arrow for floordivide code. Note that Free42/Plus42 (42S too?) MOD is really floormod. Q should be floorquotient to match. Example, Python use floordivide/floormod: divmod(y,x) == (y//x, y%x) >>> Y, X = 8*10**11+2, 4 >>> divmod(Y, X) (200000000001L, 2L) >>> divmod(Y, X) (200000000001L, 2L) OP code, it seems Q is truncated quotient, R is floormod. Or, if you want truncated quotient, R should match that. Either way, invariant Y = Q*X+R should hold. (Y) (X) "RQ" > (2e11) (+2) ? (Y) (X) "RQ" > (2e11) (2) ? 

« Next Oldest  Next Newest »

Messages In This Thread 
(42S) Quotient and Remainder  Werner  04052023, 09:38 AM
RE: (42S) Quotient and Remainder  Albert Chan  04052023 12:39 PM
RE: (42S) Quotient and Remainder  Werner  04052023, 01:11 PM
RE: (42S) Quotient and Remainder  Albert Chan  04052023, 01:48 PM
RE: (42S) Quotient and Remainder  Werner  04052023, 03:55 PM
RE: (42S) Quotient and Remainder  Albert Chan  04062023, 12:03 AM
RE: (42S) Quotient and Remainder  Albert Chan  04062023, 02:55 PM

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