[Free42] Numbers reformatted in program mode
|
07-22-2018, 10:33 AM
(This post was last modified: 07-22-2018 10:35 AM by ijabbott.)
Post: #1
|
|||
|
|||
[Free42] Numbers reformatted in program mode
In Free42, when entering a number such as 1.3e33 into program code, Free42 converts it to a canonical format such as 13e32, whereas the HP-42S leaves the number as typed. I'm not sure if that counts as a bug, but it does alter the program size in bytes.
ā Ian Abbott |
|||
07-22-2018, 11:03 AM
Post: #2
|
|||
|
|||
RE: [Free42] Numbers reformatted in program mode
This is documented on the Free42 FAQ:
Quote:In programs, numbers are normalized |
|||
07-22-2018, 03:24 PM
Post: #3
|
|||
|
|||
RE: [Free42] Numbers reformatted in program mode
Some background: Free42 stores numbers in programs in floating-point format, because storing them as a sequence of digits, like the real HP-42S does, would have been too slow.
Speed may not seem like an issue with Free42 today, but one of the platforms I targeted originally was PalmOS 3, which ran on 16 MHz 68000 CPUs, and on that platform, I was barely able to match the speed of the original calculator, so I optimized for speed wherever I could. Storing numbers as a sequence of digits would have meant performing a decimal-to-binary conversion each time a number line was executed, and those conversions are computationally expensive. Storing numbers in floating-point format AND as a series of digits would have taken up more memory, which was also at a premium in PalmOS. Given that the limitations that existed back then are no longer an issue, I could fix this, and I would like to, since the current behavior can be confusing, and it would be better to have byte counts that ALWAYS match those in program listings, even when they contain numbers that aren't minimal-length, like 1000 instead of 1E3. The only reason that I haven't done this yet is that it would be a lot of work, and given how minor an issue this is, it has never made it to the top of my to-do list yet... But given that that to-do list is getting shorter, some day I will get around to it. I'm not going to speculate when that will be, though! |
|||
07-22-2018, 04:40 PM
Post: #4
|
|||
|
|||
RE: [Free42] Numbers reformatted in program mode
Thanks for the answer. So can programs be imported from .raw files using a different number format (or even a different endianness for that matter)?
ā Ian Abbott |
|||
07-22-2018, 05:40 PM
Post: #5
|
|||
|
|||
RE: [Free42] Numbers reformatted in program mode
(07-22-2018 04:40 PM)ijabbott Wrote: Thanks for the answer. So can programs be imported from .raw files using a different number format (or even a different endianness for that matter)? Yes, Free42 will handle all .raw files correctly, regardless of how numbers are formatted. Endianness is not an issue since .raw files are byte streams. |
|||
07-23-2018, 07:27 AM
Post: #6
|
|||
|
|||
RE: [Free42] Numbers reformatted in program mode
(07-22-2018 03:24 PM)Thomas Okken Wrote: Given that the limitations that existed back then are no longer an issue, I could fix this, and I would like to, since the current behavior can be confusing, and it would be better to have byte counts that ALWAYS match those in program listings, even when they contain numbers that aren't minimal-length, like 1000 instead of 1E3. The only reason that I haven't done this yet is that it would be a lot of work, and given how minor an issue this is, it has never made it to the top of my to-do list yet... But given that that to-do list is getting shorter, some day I will get around to it. I'm not going to speculate when that will be, though! I kinda like it as it is, actually ;-) Cheers, Werner 41CVā ,42S,48GX,49G,DM42,DM41X,17BII,15CE,DM15L,12C,16CE |
|||
07-23-2018, 07:37 AM
Post: #7
|
|||
|
|||
RE: [Free42] Numbers reformatted in program mode
(07-22-2018 05:40 PM)Thomas Okken Wrote: Yes, Free42 will handle all .raw files correctly, regardless of how numbers are formatted. That's good to know, thanks! ā Ian Abbott |
|||
07-23-2018, 08:21 AM
Post: #8
|
|||
|
|||
RE: [Free42] Numbers reformatted in program mode
With BCD coded reals, there is no digit conversion required
A normalisation step would have to be done, so digit entry would be slightly slower than storing the number natively. It must have been fun dealing with binary floating point numbers and decimal fractions that change the number. 0.1 being converted to 0.1000000000000000055511151231257827021181583404541015625 when stored as an IEEE 64 bit number. I guess digits after the 12th can be rounded away which gives a solution. Pauli |
|||
07-23-2018, 03:25 PM
Post: #9
|
|||
|
|||
RE: [Free42] Numbers reformatted in program mode
(07-23-2018 08:21 AM)Paul Dale Wrote: With BCD coded reals, there is no digit conversion required Yes, and that's why the HP-42S can store numbers that way and still be fast. It's not as easy with base-10000 or BID, though! (07-23-2018 08:21 AM)Paul Dale Wrote: It must have been fun dealing with binary floating point numbers and decimal fractions that change the number. 0.1 being converted to 0.1000000000000000055511151231257827021181583404541015625 when stored as an IEEE 64 bit number. I guess digits after the 12th can be rounded away which gives a solution. While I was still supporting PalmOS, and therefore unable to use the Standard C Library, it was a pain. After dropping PalmOS, the code became a lot simpler: Code: sprintf(decstr, "%.15e", d); followed by the existing logic to massage the string representation to match the HP-42S display modes. |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 2 Guest(s)