▼
Posts: 1,216
Threads: 75
Joined: Jun 2011
Y.Z%X and Z^Y%X
Wouldn't Z.Y%X for the first one be better and more consistent?
Franz
▼
Posts: 4,587
Threads: 105
Joined: Jul 2005
Quote:
Y.Z%X and Z^Y%X
Wouldn't Z.Y%X for the first one be better and more consistent?
Hmmmh, RTFM for their real names and functionality ;)
Edited: 26 June 2012, 7:58 a.m.
▼
Posts: 1,216
Threads: 75
Joined: Jun 2011
Quote:
Hmmmh, RTFM for their real names and functionality ;)
Well, for me the file wp34s.op in the SVN has priority over your FM.
Posts: 3,229
Threads: 42
Joined: Jul 2006
Where did those names come from? I did use them briefly but changed them, I thought, before I committed the code.
I agree the nomenclature was inconsistent and generally poor. That's why they were changed.
 Pauli
▼
Posts: 1,216
Threads: 75
Joined: Jun 2011
Quote:
Where did those names come from? I did use them briefly but changed them, I thought, before I committed the code.
They are still in the latest wp34s.op (SVN 3172).
▼
Posts: 3,229
Threads: 42
Joined: Jul 2006
SVN 3176 is the latest now :)
 Pauli
Posts: 3,229
Threads: 42
Joined: Jul 2006
I must have committed an obsolete opcode file by mistake.
All corrected now, these two have their proper names now.
They only function in integer mode and require three positive arguments, the modulus being greater than 1.
I'd have liked to make their support more widspread (negatives & reals) but we lack the flash space. Still, I hope someone finds the useful.
 Pauli
▼
Posts: 556
Threads: 9
Joined: Jul 2007
And what about the (halfpromised earlier) MOD function hp41, hp42 style? Shouldn't be that hard to put in? Like RMDR x<0? RCLL.
Cheers,
▼
Posts: 3,229
Threads: 42
Joined: Jul 2006
The difference is these functions already existed in flash but weren't exposed. They are required for the primality tester.
MOD would be new code that has to work in integer and real modes and do the appropriate things with carry & overflow (whatever they are).
The code to do MOD is straightforward:
a MOD b = a RMDR b + (if a*b < 0 then b)
 Pauli
▼
Posts: 556
Threads: 9
Joined: Jul 2007
▼
Posts: 3,229
Threads: 42
Joined: Jul 2006
I didn't commit to doing it :)
A user code routine in the library is possible now.
 Pauli
▼
Posts: 556
Threads: 9
Joined: Jul 2007
Thanks again for that. I've strictly specific use of MOD so it's ok.
Another little thing, have you guys considered some different settings to the H.MS display format? (For example through flags  we've got so many of them, I can't imagine who would need them.) I'd have some use of it if it showed rounded to the nearest second result.
Cheers,
Posts: 3,229
Threads: 42
Joined: Jul 2006
How about this:
LBL'MOD'
LocR 010
[cmplx]STO .00
RMDR
STOS .02
[cmplx]RCL .00
SIGN
x[<>] Y
SIGN
x=? Y
SKIP 005
RCL .00
STO+ .02
STO L
RCLS .02
RTN
RCL .00
BACK 004
END
Put it into flash and call via XEQ'MOD'
 Pauli
▼
Posts: 255
Threads: 22
Joined: May 2011
Whoa! That looks way more complicated than the one I have used for quite some time (from the Assembler manual, Figure 4.2):
// Source file(s): wp34slib.dat
0001 LBL'MOD'
0002 RMDR
0003 RCL L
0004 x[<>] Y
0005 x<0?
0006 +
0007 RTN
0008 END
// 8 total words used.
// 9 total words used.
// 7 single word instructions.
// 1 double word instructions.
▼
Posts: 3,229
Threads: 42
Joined: Jul 2006
But my version works :)
Try 16 ENTER 3 XEQ'MOD'
Your version returns 4 which is clearing incorrect.
Mine returns 1 which is.
Mine also sets L correctly and preserves the stack properly.
Inputs RMDR MOD
16 3 1 1
16 3 1 2
16 3 1 2
16 3 1 1
You have to add the modulus back in only if the signs of the original numbers are different  your code doesn't do this.
Still, I'm sure it can be shaved a few instructions.
 Pauli
Edited: 27 June 2012, 5:51 p.m.
▼
Posts: 255
Threads: 22
Joined: May 2011
In all my years working with modular numbers in cryptographic applications I have never heard of a negative modulus! Very new to me. I am not sure what this would mean in physical sense considering a modular set is usually described as [0..(modulus1)]. Perhaps I am too sheltered. :)
Alas, mine does all I need it to do. YMMV
▼
Posts: 3,229
Threads: 42
Joined: Jul 2006
I'm just emulating the behaviour of the 41/42 MOD function which deals with negative modulus this way. Might as well do a complete job or not at all :)
 Pauli
▼
Posts: 255
Threads: 22
Joined: May 2011
I really should know better than to argue with you on mathematical grounds! Once again, you are absolutely correct! I looked up the IEEE 754 definition and, lo and behold, negative modulus is OK. Cool!
Maybe it is the modular equivalent of an imaginary number... :)
Mind you, I think I will stick with my simpler version since, for all practical applications that I use it for, it was a treat  and I can understand it.
Cheers...
Posts: 1,216
Threads: 75
Joined: Jun 2011
Quote:
In all my years working with modular numbers in cryptographic applications I have never heard of a negative modulus!
Yes, you're right in a mathematical sense, there a modulus is in fact defined as positive number. But in mathematics (and also in your menttioned crypto apps) I doubt that negative numbers in modulo calculations are usual at all.
But for computers and calculators MOD is really defined as Pauli showed in his list: MOD is negative if both arguments have different signs. I've tried it with 4 different calcultors (HP50g, HP39gII, TI92+ and TINspire), and all 4 return exactly the values of Pauli's table.
BTW, that's exactly why I don't think this RMDR function is very useful when all other calcs have the usual MOD function.
Franz
Posts: 1,216
Threads: 75
Joined: Jun 2011
Quote:
Still, I'm sure it can be shaved a few instructions.
I've made a version with 2 steps less, and it only needs 2 local regs (no need to save the complete stack) and also preserves LastX. Without LastX it would even be 5 steps less.
LBL'MOD'
LocR 02
cpx STO .00
RMDR
RCL L
cpx x<> .00
SIGN
x<>y
SIGN

x!=0?
x<> .00
RCL+ .01
RCL .00
STO L
DROP
END
Franz
Edited: 27 June 2012, 7:00 p.m.
