Post Reply 
(42S) (& 41C): Ceiling (& Floor) Function Programme
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 }
01>LBL "CEIL"
02 IP
03 X<>Y
04 X<> ST L
05 X>Y?
06 ISG ST Y
07 X<=Y?
08 X<> ST L
09 X<>Y
10 END

Combined with FLOOR:

Code:
00 { 41-Byte Prgm }
01>LBL "FLOOR"
02 IP
03 X<>Y
04 X<> ST L
05 X<Y?
06 DSE ST Y        always skips
07 LBL 00            nop
08 GTO 00
09>LBL "CEIL"
10 IP
11 X<>Y
12 X<> ST L
13 X>Y?
14 ISG ST Y         always skips
15>LBL 00           not a nop ;-)
16 X<> ST L
17 X<>Y
18 END

shortest (to my knowledge) without stack preservation (CEIL must end with an END as the ISG skips)

Code:
>LBL "FLOOR"
 RCL ST X
 1
 MOD
 -
 RTN
>LBL "CEIL"
 ENTER
 IP
 X<Y?
 ISG ST X
 END

All routines are 41-compatible.

Cheers, Werner

41CV†,42S,48GX,49G,DM42,DM41X,17BII,15CE,DM15L,12C,16CE
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: HP 42S: Ceiling Function Programme - Werner - 02-01-2017 07:07 AM



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