(42S) (& 41C): Ceiling (& Floor) Function Programme
|
01-31-2017, 05:39 PM
(This post was last modified: 06-15-2017 01:53 PM by Gene.)
Post: #1
|
|||
|
|||
(42S) (& 41C): Ceiling (& Floor) Function Programme
Behold a programme to implement the ceiling function for reals.
I would be grateful for improvements. Code:
|
|||
01-31-2017, 09:20 PM
(This post was last modified: 01-31-2017 09:21 PM by Didier Lachieze.)
Post: #2
|
|||
|
|||
RE: HP 42S: Ceiling Function Programme
Using only the stack registers X & L:
Code: 00. { 23-Byte Prgm } |
|||
02-01-2017, 06:14 AM
Post: #3
|
|||
|
|||
RE: HP 42S: Ceiling Function Programme
Bravo Didier!
This version is shorter but yours is more elegant. Code:
|
|||
02-01-2017, 07:07 AM
(This post was last modified: 02-01-2017 07:09 AM by Werner.)
Post: #4
|
|||
|
|||
RE: HP 42S: Ceiling Function Programme
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 41CV†,42S,48GX,49G,DM42,DM41X,17BII,15CE,DM15L,12C,16CE |
|||
02-01-2017, 07:24 AM
Post: #5
|
|||
|
|||
RE: HP 42S: Ceiling Function Programme
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 |
|||
02-01-2017, 08:09 AM
Post: #6
|
|||
|
|||
RE: HP 42S: Ceiling Function Programme
Werner, for this programme I have a size of 38 Bytes.
Code:
|
|||
02-01-2017, 09:20 AM
(This post was last modified: 02-01-2017 09:45 AM by Werner.)
Post: #7
|
|||
|
|||
RE: HP 42S: Ceiling Function Programme
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 41CV†,42S,48GX,49G,DM42,DM41X,17BII,15CE,DM15L,12C,16CE |
|||
02-01-2017, 09:52 AM
Post: #8
|
|||
|
|||
RE: HP 42S: Ceiling Function Programme
There is always the 34S's single step version
- Pauli |
|||
02-07-2017, 02:20 AM
Post: #9
|
|||
|
|||
RE: HP 42S (& 41C): Ceiling (& Floor) Function Programme
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. |
|||
02-07-2017, 02:33 AM
Post: #10
|
|||
|
|||
RE: HP 42S (& 41C): Ceiling (& Floor) Function Programme
This gets my vote for best use of a hyperbolic function
- Pauli |
|||
02-07-2017, 11:42 PM
Post: #11
|
|||
|
|||
RE: HP 42S (& 41C): Ceiling (& Floor) Function Programme
(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! --Bob Prosperi |
|||
02-09-2017, 09:16 AM
(This post was last modified: 02-09-2017 09:16 AM by Dieter.)
Post: #12
|
|||
|
|||
RE: HP 42S (& 41C): Ceiling (& Floor) Function Programme | |||
02-09-2017, 08:33 PM
(This post was last modified: 02-12-2017 08:00 PM by Gerson W. Barbosa.)
Post: #13
|
|||
|
|||
RE: HP 42S (& 41C): Ceiling (& Floor) Function Programme
(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. ------------------- |
|||
05-15-2020, 11:59 PM
Post: #14
|
|||
|
|||
RE: (42S) (& 41C): Ceiling (& Floor) Function Programme
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 |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)