(42S) (& 41C): Ceiling (& Floor) Function Programme - 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) (& 41C): Ceiling (& Floor) Function Programme (/thread-7691.html) |
(42S) (& 41C): Ceiling (& Floor) Function Programme - Gerald H - 01-31-2017 05:39 PM Behold a programme to implement the ceiling function for reals. I would be grateful for improvements. Code:
RE: HP 42S: Ceiling Function Programme - Didier Lachieze - 01-31-2017 09:20 PM Using only the stack registers X & L: Code: 00. { 23-Byte Prgm } RE: HP 42S: Ceiling Function Programme - Gerald H - 02-01-2017 06:14 AM Bravo Didier! This version is shorter but yours is more elegant. Code:
RE: HP 42S: Ceiling Function Programme - Werner - 02-01-2017 07:07 AM Time to delve into my archives.. Using only X and L, and saving original in L (what I call a perfect function): Code: 00 { 19-Byte Prgm } Combined with FLOOR: Code: 00 { 41-Byte Prgm } shortest (to my knowledge) without stack preservation (CEIL must end with an END as the ISG skips) Code: >LBL "FLOOR" All routines are 41-compatible. Cheers, Werner RE: HP 42S: Ceiling Function Programme - Paul Dale - 02-01-2017 07:24 AM Why not CEIL as: CHS XEQ"FLOOR" CHS? That should be shorter, although LastX won't be perfect. Use a numeric label at the start of the FLOOR routine to save more bytes. - Pauli RE: HP 42S: Ceiling Function Programme - Gerald H - 02-01-2017 08:09 AM Werner, for this programme I have a size of 38 Bytes. Code:
RE: HP 42S: Ceiling Function Programme - Werner - 02-01-2017 09:20 AM Gerald: 38 on a 42S, 41 on.. a 41 as there it includes the END ;-) And it was written for a 41 originally. Paul: indeed, not 'perfect' any more, and it uses a subroutine level. Werner RE: HP 42S: Ceiling Function Programme - Paul Dale - 02-01-2017 09:52 AM There is always the 34S's single step version - Pauli RE: HP 42S (& 41C): Ceiling (& Floor) Function Programme - Gerson W. Barbosa - 02-07-2017 02:20 AM Not perfect, 42S only: 00 { 17-Byte Prgm} 01 LBL "FLOOR" 02 IP 03 LASTX 04 FP 05 X<0? 06 COSH 07 IP 08 - 09 END 00 { 17-Byte Prgm} 01 LBL "CEIL" 02 +/- 03 XEQ "FLOOR" 04 +/- 05 .END. RE: HP 42S (& 41C): Ceiling (& Floor) Function Programme - Paul Dale - 02-07-2017 02:33 AM This gets my vote for best use of a hyperbolic function - Pauli RE: HP 42S (& 41C): Ceiling (& Floor) Function Programme - rprosperi - 02-07-2017 11:42 PM (02-07-2017 02:33 AM)Paul Dale Wrote: This gets my vote for best use of a hyperbolic function 1 + !! I really had to look hard at this. Gave me a big smile. Thanks for that Gerson! RE: HP 42S (& 41C): Ceiling (& Floor) Function Programme - Dieter - 02-09-2017 09:16 AM (02-07-2017 02:20 AM)Gerson W. Barbosa Wrote: Not perfect, 42S only: I guess using SIGN and + instead of COSH and – would have been far too trivial ?-) Dieter RE: HP 42S (& 41C): Ceiling (& Floor) Function Programme - Gerson W. Barbosa - 02-09-2017 08:33 PM (02-09-2017 09:16 AM)Dieter Wrote:(02-07-2017 02:20 AM)Gerson W. Barbosa Wrote: Not perfect, 42S only: That's what used to work both on my HP-15C and on my HP-32S II. But you're right, SIGN & + are way better than COSH & - on the HP-42S (one byte shorter and HP-41 compatible). Thanks for the improvement! On the HP-42S we can make it also one step shorter: 00 { 16-Byte Prgm } 01 LBL "FLOOR" 02 IP 03 LASTX 04 FP 05 X<0? 06 SIGN 07 BASE+ 08 END Gerson. ------------------- RE: (42S) (& 41C): Ceiling (& Floor) Function Programme - Juan14 - 05-15-2020 11:59 PM From all the programs, the one that uses the command MOD presented by Werner is the most interesting for me, if you replace 1 by -1 before the command MOD you get the CEIL function. This next modification requires that you enter a number and 1 if you want the FLOOR function or -1 if you want the CEIL function 00 { 12-Byte Prgm } 01 LBL “IFS” 02 RCL ST Y 03 X<>Y 04 MOD 05 - 06 END Examples: 2.5 [ENTER] 1 [XEQ] [IFS] returns 2 2.5 [ENTER] -1 [XEQ] [IFS] returns 3 |