Post Reply 
Yet another Fibonacci mini-challenge (HP-42S/Free42)
01-09-2019, 05:20 AM
Post: #21
RE: Yet another Fibonacci mini-challenge (HP-42S/Free42)
(12-06-2018 11:30 AM)Thomas Okken Wrote:  NOT +/-

That's actually three bytes, not two, but 1 BASE+ is four bytes, so it does save one byte.

Anyway, now I see why this cleverness causes this implementation to fail for n > 50: that's where the BASE functions' 36-bit arithmetic goes out of range. You do need to use IP if you want to avoid that limitation.

1 + IP takes an extra step. However, we could use IP and save one step instead:

Code:

00 { 23-Byte Prgm }
01▸LBL "FIB"
02 0.5
03 ASINH
04 ×
05 COSH
06 0.8
07 SQRT
08 ×
09 IP
10 END

This even works for F0. Too bad the working range is from n=0 through n=26 on the actual 42S. On Free42 it’s even worse: it will fail for n=1, because IP(0.99999999999999999999...99) is of course zero. IP can be replaced with RND, provided the display mode is set to FIX 0 or FIX 1, definitely not a good idea.

But the limitation can still be overcome by using IP while keeping the original number of steps:

Code:

00 { 24-Byte Prgm }
01▸LBL "FIB"
02 0.5
03 ASINH
04 ×
05 COSH
06 0.8
07 SQRT
08 ×
09 →HR
10 IP
11 END

The range on the real 42S is still limited to [1..50], but on Free42 is about [1..160+] (to be checked).
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: