The Museum of HP Calculators

HP Forum Archive 19

[ Return to Index | Top of Index ]

New HP-15C simulator
Message #1 Posted by Greg Hewgill on 22 June 2010, 5:40 a.m.

I've put together a new HP-15C simulator at http://hp15c.com. It does almost everything, with some minor exceptions as noted on the About page. I'm continuing to work on it to implement the missing bits, so expect updates.

Please try it out - feedback, bug reports, and even contributions are welcome!

      
Re: New HP-15C simulator
Message #2 Posted by Namir on 22 June 2010, 8:53 a.m.,
in response to message #1 by Greg Hewgill

Greg,

I checked the SOLVE feature with my usual test function, and your simulator came through with flying colors.

I want to salute your valiant effort to create an HP-15C simulator for browsers. Not an easy job, especially if you are using Javascript (are you?).

Namir

Edited: 22 June 2010, 8:59 a.m.

            
Re: New HP-15C simulator
Message #3 Posted by Greg Hewgill on 22 June 2010, 3:25 p.m.,
in response to message #2 by Namir

Thanks! It is indeed written in Javascript (which is a pretty capable language, all things considered). The "Source" link on the site links to the source repository if you want to have a look.

      
Re: New HP-15C simulator
Message #4 Posted by MK-52 on 22 June 2010, 10:35 a.m.,
in response to message #1 by Greg Hewgill

SIN(PI = 3.14159265359) = 1.224646799e-16
SIN(3.14159265) = 3.589793029e-09
SIN(0.01) = 9.999833334e-03
SIN(PI-0.01) = 9.999833334e-03
TAN(355/226) = -7.497258179e+06

Very accurate trig. BTW, CHS doesn't work in EEX.

            
Re: New HP-15C simulator
Message #5 Posted by MK-52 on 22 June 2010, 10:48 a.m.,
in response to message #4 by MK-52

If unimplemented functions is used in looping program, for example, Solver and Integration, the simulator keeps showing error messages. I think this is a small problem.

Edited: 22 June 2010, 10:49 a.m.

            
Re: New HP-15C simulator
Message #6 Posted by Greg Hewgill on 22 June 2010, 3:26 p.m.,
in response to message #4 by MK-52

The trig functions come straight out of the Javascript "Math.*" library, so I can't claim any credit for their accuracy. :)

I'll add the CHS in EEX bug to the known issues list.

      
Re: New HP-15C simulator
Message #7 Posted by hugh steers on 22 June 2010, 3:00 p.m.,
in response to message #1 by Greg Hewgill

some missing complex trigs.

also, try adding 0.1 ten times, then press H.MS to get 0.5960 opps!

large factorials go bad, also in FIX 9, you dont get the exponent.

otherwise neat!

keep up the good work.

            
Re: New HP-15C simulator
Message #8 Posted by Greg Hewgill on 22 June 2010, 3:30 p.m.,
in response to message #7 by hugh steers

Thanks! The missing complex trig functions are noted on the known issues list. I'll have a look at that ->H.MS rounding problem.

I suspect the large factorials are due to some display rounding problems, especially with numbers slightly less than 1e100. Which number did you notice specifically?

                  
Re: New HP-15C simulator
Message #9 Posted by hugh steers on 23 June 2010, 6:49 a.m.,
in response to message #8 by Greg Hewgill

try FIX 9. then 69!

                        
Re: New HP-15C simulator
Message #10 Posted by Greg Hewgill on 23 June 2010, 7:46 a.m.,
in response to message #9 by hugh steers

Thanks, should be fixed now.

                  
Re: New HP-15C simulator
Message #11 Posted by Mike T. on 23 June 2010, 3:06 p.m.,
in response to message #8 by Greg Hewgill

Try 48.0 minus 47.8 then subtract 0.2 from the answer, the result should be zero - but it isn't so I know you are doing binary math.

Mike T.

                        
Re: New HP-15C simulator
Message #12 Posted by Greg Hewgill on 23 June 2010, 3:33 p.m.,
in response to message #11 by Mike T.

Yes, that's true. I don't claim to be doing BCD math, that would be a substantial amount more work (but still possible). The simulator uses the native Javascript math library (as implemented in your browser) for all arithmetic.

                              
Re: New HP-15C simulator
Message #13 Posted by hugh steers on 24 June 2010, 2:32 p.m.,
in response to message #12 by Greg Hewgill

is there a JS "decimal" type, or is that java only?

alternatively, you could pull a trick to "fix" these sorts of problems when working in binary as follows:

a + b = a <+> b  if |a <+> b| >= eps*|a|
      = 0 otherwise

where <+> represents computed addition rather than mathematical addition and eps is epsilon eg 10^-15

use the same idea for subtraction.

some real world calculators actually work in binary and they must do a trick like this, because i've tried to embarrass them with a binary rounding error and not been successful.

      
Re: New HP-15C simulator
Message #14 Posted by Steve Simpkin on 22 June 2010, 5:25 p.m.,
in response to message #1 by Greg Hewgill

Very nice!!! It even works using the browser on my Android phone.

            
Re: New HP-15C simulator
Message #15 Posted by Egan Ford on 22 June 2010, 6:02 p.m.,
in response to message #14 by Steve Simpkin

I tried it on my iPad. Works too. However "test" reported errors:

Unimplemented: complex log

Fail: 45g)

Update: Test also failed on Firefox, fail: 3^.

Test now working on iPad. I just turned it sideways, reloaded the page so I could see the registers and test passed after 1 min 45 sec.

Hmmmm.... Just tested on iPad again, this time the orientation is the same as my failed test and it passed.

Hmmmm..... 4th try. I cannot get it to fail again on the iPad. BTW, no need for 'h' on the iPad, fingers work great. :-)

Update 2: Firefox fails repeatably (fail: 3^). iPad works every time now. Unsure what the original issue was.

Feature requests:

Sound (click), some type of visual button press notification.

Excellent work. Thanks!

Update 3:

I tested with Safari 5.0. Also failed like Firefox 3.6.3 with "fail: 3^". If I press test again I get the error above (complex log). BTW Safari screams compared to Firefox.

Chrome is also a screamer and passes, but a retest generates the "complex log" error.

I speculate the "complex log" error is erroneous.

Update 4:

Just got the "fail 3^" with Chrome. I cannot get Chrome to pass again without restarting Chrome. After that I got 3 passes and then non-stop fail 3^.

Edited: 22 June 2010, 6:30 p.m.

                  
Re: New HP-15C simulator
Message #16 Posted by Greg Hewgill on 23 June 2010, 4:31 a.m.,
in response to message #15 by Egan Ford

Wow, thanks for all the testing! I suspect many of those failures were due to the test function not resetting some critical flags (like the Complex flag) before running the test. Since the test ends with C set, this was sort of a problem. I've updated the script so the Test runs twice on my system, and would be interested to see whether that fixes the issues you saw.

                        
Re: New HP-15C simulator
Message #17 Posted by Egan Ford on 23 June 2010, 8:46 a.m.,
in response to message #16 by Greg Hewgill

Complex Log issue fixed, however:

Firefox 3.6.3, Safari 5.0 (OS/X 10.6.4):

The page at http://hp15c.com/ says:
fail: 3^
result: 352.00000000000006
expected: 352
diff: 2.220446049250313e-16

Chrome 5.0.375.70 (OS/X 10.6.4). Passed 3 times, then I closed the pop-up, clicked on the image again to get a new session and then test failed with:

The page at http://hp15c.com/ says:
fail: 3^
result: 352.00000000000006
expected: 352
diff: 2.220446049250313e-16
2.220446049250313e-16 is a familiar number with 64-bit floats. The "diff:" is the relative machine precision (i.e., the smallest number + 1 > 1), e.g.:
perl -e '$eps=1;while($eps+1>1){$eps/=2.0}$eps*=2;print"$eps\n"'
and
#include <stdio.h>
int main(void)
{
    double eps = 1.0;
    while(eps + 1.0 > 1.0)
        eps /= 2.0;
    eps *= 2.0;
    printf("Epsilon is %.14e\n", eps);
}
yield:
2.22044604925031e-16
Rounding issues?

Why this works then fails on Chrome is odd. It should be consistent one way or another. Are all variables/arrays initialized? Does that question make sense for JavaScript?

Edited: 23 June 2010, 8:50 a.m.

                              
Re: New HP-15C simulator
Message #18 Posted by Greg Hewgill on 23 June 2010, 4:45 p.m.,
in response to message #17 by Egan Ford

The nondeterministic behaviour is indeed odd. I haven't seen that on any of the browsers I've tried, but I'll investigate.

            
Re: New HP-15C simulator
Message #19 Posted by Bart (UK) on 23 June 2010, 7:05 a.m.,
in response to message #14 by Steve Simpkin

And on my Nokia 5800!! Just fits in on Full Screen mode.

      
Re: New HP-15C simulator
Message #20 Posted by Walter B on 22 June 2010, 6:09 p.m.,
in response to message #1 by Greg Hewgill

Good work!

Just pressing EEX without any preceding digit will not execute properly. You may even end with one stack level in a different format, i.e. displaying less decimals.

            
Re: New HP-15C simulator
Message #21 Posted by Greg Hewgill on 23 June 2010, 4:44 a.m.,
in response to message #20 by Walter B

Indeed, that does look like it's doing the wrong thing. Will fix!

      
Re: New HP-15C simulator
Message #22 Posted by Chuck on 23 June 2010, 1:52 p.m.,
in response to message #1 by Greg Hewgill

Nice simulator. Through trial and error I found that values can be as large as 1x10^308. Though only the last two digits are displayed in the exponent, all three are actually still there because if you Log the value you get 308.

This means for large factorials (or for any large number) the integer part of the log of the answer is the correct exponent. For factorials I believe you can go up to 170! which shows

7.2574     06

But logging the number shows the exponent is actualyl 306. Possibly an improvement over an actual 15C, as long as you are aware of this when dealing with large numbers (like e^500).

CHUCK

Edited: 23 June 2010, 1:58 p.m.

            
Re: New HP-15C simulator
Message #23 Posted by Greg Hewgill on 23 June 2010, 3:45 p.m.,
in response to message #22 by Chuck

Good catch - that's one of the situations I alluded to in the fine print, where "the numeric display is known to be totally wrong". :)

Behind the scenes, the calculator simulator uses the native Javascript Math library as implemented in your browser, which has the IEEE 754 double precision exponent range of approximately -308 to 308. I plan to detect such out of bounds display (beyond -99 to 99) and blink the result as a real 15C would do, rather than attempt to improve upon it.

      
Re: New HP-15C simulator
Message #24 Posted by Mike T. on 23 June 2010, 2:59 p.m.,
in response to message #1 by Greg Hewgill

Very cool - looks great and the buttons move too.

Mike T.

      
Re: New HP-15C simulator
Message #25 Posted by megarat on 23 June 2010, 4:52 p.m.,
in response to message #1 by Greg Hewgill

Please don't take me as a troll, because I'm honestly curious (plus a huge fan of the 15c).

Ignoring (a) the joy of creating such an application, and (b) the joy of dinking around with such an application, does anyone find that web-based calculator sims like this have practical application?

Loading it on a webphone sounds semi-practical ... but not nearly as practical as a native RPN calculator app. IMHO, most of these web apps are missing the features that make them truly useful, e.g., copying/pasting the results from the calculator into another app.

If I'm missing something, please enlighten me!

Edited: 23 June 2010, 4:53 p.m.

            
Re: New HP-15C simulator
Message #26 Posted by Greg Hewgill on 24 June 2010, 3:34 a.m.,
in response to message #25 by megarat

I think the idea of calculator simulators does not necessarily lean toward the "useful" side. Although some enthusiasts (like me and others that are probably found here) will use a simulator as their desktop calculator for nostalgic reasons (or even to provoke questions from curious bystanders), I don't think they are intended to be general purpose replacements for a fully functional calculator program or service.

For the 15C specifically, all of the "advanced" functions offered (complex, matrix, integration, solver) are provided in a much more usable, useful, and practical way by other services such as Wolfram Alpha. Surely you're aware of how tedious it is to actually enter matrix data into a 15C, for example.

Having said that, creating a web app does not preclude also creating a desktop app. A web user interface is an easy, quick, and widely accessible way of getting code out there that people can run instantly. The code is written in JavaScript, which is one of the most portable languages around today. I wouldn't rule out creating a corresponding application for desktop or mobile use. In fact, since it's open source, I would even encourage that!

I hope you enjoy the calculator simulators. That's what it's all about.

                  
Re: New HP-15C simulator
Message #27 Posted by megarat on 24 June 2010, 1:40 p.m.,
in response to message #26 by Greg Hewgill

Thanks for your thoughts. Simulators like this definitely put a smile on my face (I especially like the web-based slide rule simulators), but I wasn't sure if there was something more to it than the fun/novelty.

I also use a 15c simulator (application) as a calculator in Mac OS X, but it has the added advantage of being able to give/receive data via copy/paste, which I use routinely. (IIRC, it will also save/load programs to disk, although I've never used that feature since, as I'm already using a computer, it's typically easier to write the code I need in something else.)

Edited: 24 June 2010, 1:41 p.m.

      
Re: New HP-15C simulator
Message #28 Posted by BobVA on 23 June 2010, 9:56 p.m.,
in response to message #1 by Greg Hewgill

Nice job!

The PSE function needs some attention - looks like it puts the X register up on the display, but doesn't really pause to show it.

Cheers, Bob

            
Re: New HP-15C simulator
Message #29 Posted by Greg Hewgill on 24 June 2010, 3:35 a.m.,
in response to message #28 by BobVA

Good catch, I had that disabled for the self-test. I'll find a better way to handle that within the test, and enable PSE for interactive use.

      
Re: New HP-15C simulator
Message #30 Posted by Thomas Klemm on 24 June 2010, 12:20 p.m.,
in response to message #1 by Greg Hewgill

Thanks for the contribution. What do you think, how difficult would it be to port Eric Smith's Nonpareil to JavaScript instead?

Best regards
Thomas


[ Return to Index | Top of Index ]

Go back to the main exhibit hall