[42S] MANT Challenge

01222014, 09:40 AM
Post: #1




[42S] MANT Challenge
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.00000000001e01 9.99999999999 9.99999999999e499 Good luck, Werner 41CV†,42S,48GX,49G,DM42,DM41X,17BII,15CE,DM15L 

01222014, 12:23 PM
Post: #2




RE: [42S] MANT Challenge
(01222014 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 HP15C: 9 steps on my first attempt. Code:
Regards, Gerson. 

01222014, 12:38 PM
Post: #3




RE: [42S] MANT Challenge
Fails for 2e02 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 41CV†,42S,48GX,49G,DM42,DM41X,17BII,15CE,DM15L 

01222014, 01:46 PM
(This post was last modified: 01222014 02:18 PM by Dieter.)
Post: #4




RE: [42S] MANT Challenge
(01222014 12:38 PM)Werner Wrote: Fails for 2e02 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 41series 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 

01222014, 02:17 PM
(This post was last modified: 01222014 02:18 PM by Werner.)
Post: #5




RE: [42S] MANT Challenge
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 41CV†,42S,48GX,49G,DM42,DM41X,17BII,15CE,DM15L 

01222014, 02:24 PM
Post: #6




RE: [42S] MANT Challenge
(01222014 02:17 PM)Werner Wrote: MANT should return the unsigned mantissa, as in the 48. Then simply add an ABS at the beginning. (01222014 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 

01222014, 02:34 PM
(This post was last modified: 01222014 02:46 PM by Werner.)
Post: #7




RE: [42S] MANT Challenge
That would indeed work, if there were such a thing as ANUM on the 42S...
Back to square one... Werner 41CV†,42S,48GX,49G,DM42,DM41X,17BII,15CE,DM15L 

01222014, 06:50 PM
Post: #8




RE: [42S] MANT Challenge
(01222014 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 XFunctions command set (without the Xmemory 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 

01222014, 07:53 PM
(This post was last modified: 01222014 08:01 PM by Dieter.)
Post: #9




RE: [42S] MANT Challenge
(01222014 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 (1E499). 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 

01222014, 08:41 PM
Post: #10




RE: [42S] MANT Challenge
(01222014 12:23 PM)Gerson W. Barbosa Wrote: This should be quite easy on the HP15C: 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:


01222014, 08:58 PM
(This post was last modified: 01222014 09:12 PM by Dieter.)
Post: #11




RE: [42S] MANT Challenge
(01222014 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 15Cversion of the 42ssolution I posted: Code: 01 ABS What do you think? EDIT: Walter  yes, I eventually found this button with the red X on it. ;) Dieter 

01222014, 09:14 PM
(This post was last modified: 01222014 09:20 PM by Gerson W. Barbosa.)
Post: #12




RE: [42S] MANT Challenge
(01222014 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 :)(01222014 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. 

01222014, 09:40 PM
Post: #13




RE: [42S] MANT Challenge
(01222014 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 

01232014, 12:40 AM
Post: #14




RE: [42S] MANT Challenge
Maybe a little boring:
Code: 00 { 39 Byte Prgm } Cheers Thomas 

01232014, 02:52 AM
(This post was last modified: 01232014 03:15 AM by Gerson W. Barbosa.)
Post: #15




RE: [42S] MANT Challenge
(01222014 08:58 PM)Dieter Wrote:(01222014 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 HP15C 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. 

01232014, 07:46 AM
Post: #16




RE: [42S] MANT Challenge
@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 ;) 41CV†,42S,48GX,49G,DM42,DM41X,17BII,15CE,DM15L 

01232014, 09:34 AM
Post: #17




RE: [42S] MANT Challenge
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:
41CV†,42S,48GX,49G,DM42,DM41X,17BII,15CE,DM15L 

01232014, 10:47 AM
Post: #18




RE: [42S] MANT Challenge
(01222014 12:38 PM)Werner Wrote: Fails for 2e02 and all 0<x<0.1 that are not 10^n Code:
Gerson. 

01232014, 11:02 AM
(This post was last modified: 01232014 11:02 AM by Werner.)
Post: #19




RE: [42S] MANT Challenge
Hi Gerson!
Fails for 1 e499, I'm afraid Werner 41CV†,42S,48GX,49G,DM42,DM41X,17BII,15CE,DM15L 

01232014, 11:05 AM
Post: #20




RE: [42S] MANT Challenge  
« Next Oldest  Next Newest »

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