[WP34s] 2 new modulo functions



#21

Y.Z%X and Z^Y%X

Wouldn't Z.Y%X for the first one be better and more consistent?

Franz


#22

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.


#23

Quote:
Hmmmh, RTFM for their real names and functionality ;-)

Well, for me the file wp34s.op in the SVN has priority over your FM.
#24

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


#25

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).

#26

SVN 3176 is the latest now :)

- Pauli

#27

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


#28

And what about the (half-promised earlier) MOD function hp41, hp42 style? Shouldn't be that hard to put in? Like RMDR x<0? RCL-L.

Cheers,


#29

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


#30

Thanks, waiting for it.


#31

I didn't commit to doing it :-)

A user code routine in the library is possible now.


- Pauli


#32

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,

#33

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


#34

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): wp34s-lib.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.

#35

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.


#36

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..(modulus-1)]. Perhaps I am too sheltered. :-)

Alas, mine does all I need it to do. YMMV


#37

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


#38

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...

#39

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, TI-92+ and TI-Nspire), 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

#40

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.


Possibly Related Threads…
Thread Author Replies Views Last Post
  [41CL] New Extra Functions version Monte Dalrymple 0 1,156 11-08-2013, 04:32 PM
Last Post: Monte Dalrymple
  HP Prime: in need of help with defining functions Alberto Candel 14 4,514 10-27-2013, 10:48 AM
Last Post: Alberto Candel
  HP Prime spreadsheet functions SanS 0 1,943 10-04-2013, 04:23 AM
Last Post: SanS
  Stats functions on the HP34S Nicholas van Stigt 5 2,101 09-24-2013, 02:45 AM
Last Post: Nick_S
  Trig Functions Howard Owen 11 3,706 09-16-2013, 02:53 PM
Last Post: Fred Lusk
  50g piecewise functions Kurt Fankhauser 6 2,425 09-15-2013, 08:01 PM
Last Post: Kurt Fankhauser
  Missing functions on the HP Prime!!!??? :-( Namir 6 2,393 08-22-2013, 08:40 AM
Last Post: Gilles Carpentier
  HP41 Functions Address Table (F.A.T.) Antoine M. Couëtte 6 2,271 07-21-2013, 02:48 AM
Last Post: Antoine M. Couëtte
  Trigonometric Functions (HP-17BII) Gerson W. Barbosa 2 1,713 04-09-2013, 11:57 PM
Last Post: Gerson W. Barbosa
  [41CL] Rescue from 'Lost Y Functions' Dan Grelinger 18 4,640 02-16-2013, 02:08 PM
Last Post: Diego Diaz

Forum Jump: