[42S] MANT Challenge - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html) +--- Forum: General Forum (/forum-4.html) +--- Thread: [42S] MANT Challenge (/thread-490.html) Pages: 1 2 |
[42S] MANT Challenge - Werner - 01-22-2014 09:40 AM On the 41, you can use Synthetic Programming to come up with a short and efficient routine that returns the mantissa. Not so on the 42S. Is anyone willing to give it a try? A few borderline cases that may foil your first attempts (on a real 42S, not Free42): 0 1.00000000001e-01 -9.99999999999 9.99999999999e499 Good luck, Werner RE: [42S] MANT Challenge - Gerson W. Barbosa - 01-22-2014 12:23 PM (01-22-2014 09:40 AM)Werner Wrote: On the 41, you can use Synthetic Programming to come up with a short and efficient routine that returns the mantissa. First attempt. Trouble with your last example. This should be quite easy on the HP-15C: 9 steps on my first attempt. Code:
Regards, Gerson. RE: [42S] MANT Challenge - Werner - 01-22-2014 12:38 PM Fails for 2e-02 and all 0<x<0.1 that are not 10^-n Fails for 9.99999999999*10^n The reason is that LOG(9.99999999999) = 1 exactly, on a real 42S Werner RE: [42S] MANT Challenge - Dieter - 01-22-2014 01:46 PM (01-22-2014 12:38 PM)Werner Wrote: Fails for 2e-02 and all 0<x<0.1 that are not 10^-n Simple solution: forget mathematics, use Alpha. Code: 01 CLA A never owned a 42s, so maybe there's a more elegant way of deleting the last two characters. This will also work on the 41-series if SCI 11 is replaced by SCI 9. Since the display mode is changed, a final command that resets it may be added. EDIT: Since always the last two characters are deleted, this only works for exponents up to ±99. The code can be adjusted accordingly, while keeping the original idea of using the internal formatting routine in Alpha mode: Code: 01 CLA This should work for all possible cases. In both routines the sign of X is preserved in the resulting mantissa. The basic idea is simple: Have X formatted in SCI mode and take the leftmost 14 characters. For X≥0 this may include a trailing "E" which is ignored when the string finally is converted back to a number. Dieter RE: [42S] MANT Challenge - Werner - 01-22-2014 02:17 PM MANT should return the unsigned mantissa, as in the 48. Exponents are 1, 2 or 3 digits, and possibly negative of course. Probably easier to remove the decimal point and use two ASTO's to X and L to get the 12 digits, then rebuild the integer in alpha and do ANUM. Would still get quite long, I think. Werner RE: [42S] MANT Challenge - Dieter - 01-22-2014 02:24 PM (01-22-2014 02:17 PM)Werner Wrote: MANT should return the unsigned mantissa, as in the 48. Then simply add an ABS at the beginning. (01-22-2014 02:17 PM)Werner Wrote: Exponents are 1, 2 or 3 digits, and possibly negative of course. Note quite that long. The original routine already worked for all exponents within ±99, and X may be zero, negative or positive. The additional routine I posted in the meantime works for any exponent. Dieter RE: [42S] MANT Challenge - Werner - 01-22-2014 02:34 PM That would indeed work, if there were such a thing as ANUM on the 42S... Back to square one... Werner RE: [42S] MANT Challenge - Dieter - 01-22-2014 06:50 PM (01-22-2014 02:34 PM)Werner Wrote: That would indeed work, if there were such a thing as ANUM on the 42S...What? No ANUM on the 42s? I thought it featured the complete X-Functions command set (without the X-memory related ones, of course). The lack of this very powerful command really is a weak point. Otherwise I could provide an even shorter version and one with a different approach. It works nicely on a 41 -- but without ANUM... #-\ But at least this routine could be used for display purposes. 8-) Code: 01 ABS ;-) Dieter RE: [42S] MANT Challenge - Dieter - 01-22-2014 07:53 PM (01-22-2014 09:40 AM)Werner Wrote: A few borderline cases that may foil your first attempts (on a real 42S, not Free42): The problem are values with a mantissa > 9,99999999988 or even > 9,99999998844 (near the end of the working range). Here the log10 will be rounded up to the next higher integer. So the idea is to divide by the next lower power of ten (which also handles cases < 0,1) and add a final adjustment if the result is beyond 10 (which is true for most cases > 1). The only left problem are values very close to the lower working limit (1E-499). Here the log10 may be returned as -499 so that a division by 10^-500 would result. This case is handled separately. Code: 01 ABS What about this one? Any errors or problematic values? At least my 35s handles all test cases correctly. And also all others I tried. Is this a solution or am I missing something? Dieter RE: [42S] MANT Challenge - Gerson W. Barbosa - 01-22-2014 08:41 PM (01-22-2014 12:23 PM)Gerson W. Barbosa Wrote: This should be quite easy on the HP-15C: 9 steps on my first attempt.I talked too soon. It wouldn't work for |x| < 0.01. Despite my bad fix attempt, which made it three times as large, it won't work for |x| < 10^-10. Code:
RE: [42S] MANT Challenge - Dieter - 01-22-2014 08:58 PM (01-22-2014 08:41 PM)Gerson W. Barbosa Wrote: I talked too soon. It wouldn't work for |x| < 0.01. Despite my bad fix attempt, which made it three times as large, it won't work for |x| < 10^-10. Here's a 15C-version of the 42s-solution I posted: Code: 01 ABS What do you think? EDIT: Walter - yes, I eventually found this button with the red X on it. ;-) Dieter RE: [42S] MANT Challenge - Gerson W. Barbosa - 01-22-2014 09:14 PM (01-22-2014 08:58 PM)Dieter Wrote:I think I am this kind of programmer, except that I didn't find a way to make that work as it should :-)(01-22-2014 08:41 PM)Gerson W. Barbosa Wrote: I talked too soon. It wouldn't work for |x| < 0.01. Despite my bad fix attempt, which made it three times as large, it won't work for |x| < 10^-10. "Category 2: ENGINEER. This type insists on making the problem more complicated than it really is. Engineers hang onto an idea tenaciously until they find a way to make it work." P.S.: Leaving for a meeting now. Will try it later. RE: [42S] MANT Challenge - Dieter - 01-22-2014 09:40 PM (01-22-2014 09:14 PM)Gerson W. Barbosa Wrote: I think I am this kind of programmerAh, yes, I found this some years ago and there is some truth in it. ;-) Usually I like short and elegant solutions like "category 3", but there is also some, err... beauty in the category 4 and 6 versions. :-) Dieter RE: [42S] MANT Challenge - Thomas Klemm - 01-23-2014 12:40 AM Maybe a little boring: Code: 00 { 39 Byte Prgm } Cheers Thomas RE: [42S] MANT Challenge - Gerson W. Barbosa - 01-23-2014 02:52 AM (01-22-2014 08:58 PM)Dieter Wrote:(01-22-2014 08:41 PM)Gerson W. Barbosa Wrote: I talked too soon. It wouldn't work for |x| < 0.01. Despite my bad fix attempt, which made it three times as large, it won't work for |x| < 10^-10. Very nice! It passes all equivalent Werner's examples for the HP-15C and others I tried. So does the following, as far as I have tested: Code:
What do you think? Still hanging on to the idea of using the RAN# register at some point in the program, but hoping to qualify for another category :-) Gerson. RE: [42S] MANT Challenge - Werner - 01-23-2014 07:46 AM @Dieter: congratulations are in order! The only thing I don't like is that it uses three stack levels (I have to complain about something) @Thomas: that's a variant of one of my attempts: Code:
Unfortunately, running time on a real 42S becomes prohibitive for larger exponents. But you can easily improve on that ;-) RE: [42S] MANT Challenge - Werner - 01-23-2014 09:34 AM It's always so much easier to improve upon someone else's code than to write your own.. 7 bytes shorter, and using only two stack levels: Code:
RE: [42S] MANT Challenge - Gerson W. Barbosa - 01-23-2014 10:47 AM (01-22-2014 12:38 PM)Werner Wrote: Fails for 2e-02 and all 0<x<0.1 that are not 10^-n Code:
Gerson. RE: [42S] MANT Challenge - Werner - 01-23-2014 11:02 AM Hi Gerson! Fails for 1 e-499, I'm afraid Werner RE: [42S] MANT Challenge - Gerson W. Barbosa - 01-23-2014 11:05 AM (01-23-2014 11:02 AM)Werner Wrote: Hi Gerson!So does the HP-15C version for 1e-99... I think I'll stick to the WP 34S and use MANT instead :-) Gerso. |