Free42 : An HP-42S Calculator Simulator

Related tags

Calculator free42
Overview
-------------------------------------------------------------------------------
Free42 is a software clone of the Hewlett-Packard 42S calculator. If you know
how to use an HP-42S, you know how to use Free42.
If you're new to the HP-42S and its clones, you may want to take a peek at the
manual. You can find documentation at https://thomasokken.com/free42/#doc

The remainder of this README file covers some miscellaneous tidbits that I had
no other decent place to put.


-------------------------------------------------------------------------------
Binary vs. Decimal
Starting with release 1.4, Free42 can be built with binary or with decimal
floating point. Building the binary versions works as always (just say "make");
to build the decimal versions, set the BCD_MATH environment variable, or use
"make BCD_MATH=1".
When switching between building the decimal and binary version (or vice versa),
be sure to do "make clean", to avoid linking the wrong objects.
When building the Windows version using Visual C++, choose the Free42Binary or
Free42Decimal projects; these projects are set up so that all output files are
written to separate directories (ReleaseBinary, ReleaseDecimal, DebugBinary,
DebugDecimal), so you can switch between these projects without having to worry
about cleaning up object files.


-------------------------------------------------------------------------------
Building on Raspbian 10

# apt install libgtk-3-dev
# apt install libasound2-dev
$ git clone https://github.com/thomasokken/free42.git
$ cd free42/gtk
$ make BCD_MATH=1 AUDIO_ALSA=1


-------------------------------------------------------------------------------
Creating Free42 build environment in FreeBSD

Create VirtualBox VM (using VirtualBox 5.2.22)
Install FreeBSD-12.0-RELEASE-amd64-dvd1.iso

then:

pkg install gnome3
pkg install xorg
pkg install virtualbox-ose-additions

in /etc/fstab, added:
proc           /proc       procfs  rw  0   0

in /etc/rc.conf, added:
vboxguest_enable="YES"
vboxservice_enable="YES"
dbus_enable="YES"
hald_enable="YES"
gdm_enable="YES"
gnome_enable="YES"

That brings up the desktop.
Now, some more stuff:

pkg install devel/pkgconf
pkg install devel/gmake


-------------------------------------------------------------------------------
About the character sets:
('bigchars' and 'smallchars' arrays in core_display.c)

The top half of the 256 character codes are like the bottom half,
with these exceptions:
0x80: thin colon (':') (looks different than regular colon),
      while 0x00 is a calculator-style divide sign (superposition
      of ':' and '-')
0x81: small 'Y'; 0x01: multiply sign
0x8a: displays 'LF' character (small 'L' and small 'F',
      slightly offset, squeezed into one character cell);
      0x0a: actual linefeed (move to next line of display).

The bigchars array contains 130 characters, in 5x8 pixel cells,
corresponding to codes 0-129. Char 10 is the 'LF' ligature.

Note: the 'x:' and 'y:' legends for the standard X and Y register display
are built from 0x78 (lowercase x), 0x81 (small 'Y'), and 0x80 (thin ':').
Note: 0x01 (multiply) is different than 0x78 (lowercase x) (it is 1 pixel
higher).


-------------------------------------------------------------------------------
HP-42S bugs that I found:

If you activate the CUSTOM menu in KEYASN mode, go to its third row, and then
switch to LCLBL mode, you get a menu row with labels "L", "M", "N", "O", "@",
"XEQ"; these keys activate the commands XEQ ST Z, XEQ ST Y, XEQ ST X, XEQ ST L,
XEQ 117, XEQ 118.
These commands do actually work, but entering the corresponding labels into a
program is a bit tricky...

->POL and ->REC with a real number in X reject a string in Y (good), accept a
real number in Y (good), accept a complex number in Y but only use its real
part (undocumented and not very useful), and accept real and complex matrices
in Y with weird results. I'd say the complex and matrix cases are all bugs,
resulting from a missing parameter type check.

If MATA, MATB, or MATX is the indexed matrix, and SIMQ resizes it to a smaller
size, IJ aren't set to (1, 1) as they usually are when the indexed matrix is
resized (though DIM or SIZE). As a result, IJ can end up pointing outside the
allocated elements, and RCLEL and STOEL can then produce wacky results.

HP-42S bugs that others have found:

When COMB or PERM are invoked with bad arguments (e.g. X > Y), "Invalid Data"
is returned (good), but all subsequent invocations of those two functions also
yield that message, even if the parameters are now correct (bad). This
condition can be cleared up by performing an operation that affects LASTx (but
not STO ST L). Apparently some rev. B models do not have this bug; I have read
that the original problem was a hardware bug, for which rev. B introduced a
software workaround; somewhere in the rev. B production run the hardware bug
was fixed, but now the software workaround would *cause* the bug. The bug also
exists in all rev. C models, apparently (it does in mine, and in Emu42 when run
with a rev. C ROM!).
I'm curious as to why a couple of basic, straightforward instructions like COMB
and PERM would be sensitive to a hardware bug (and *only* they, apparently),
but who am I to question what I've heard others report? I'm not about to spend
weeks poring over ROM disassemblies to make sure...

In LINΣ mode, summing a matrix is buggy. I have seen it sum only the first row,
and report a bogus value back in X (8.47216900137e-489), and also seen it say
Insufficient Memory when that clearly wasn't true; I have heard a report from
someone else about the machine even locking up to the point where it needs a
hard reset.

In some versions, in LINΣ mode, Σ+ and Σ- do not update LASTx. I read about
this in a manual addendum from HP; however, I cannot reproduce this, neither on
my real HP-42S nor on Emu42 (both rev. C ROM).

I have also heard a report that FCSTX is buggy in PWRF mode; I have not been
able to confirm this yet but there appears to be more I have to read about it.
Probably depends on your ROM version; I tested with rev. C but it seemed fine.

Not sure if this is a bug or not:

When KEYX or KEYG are used to reprogram the ▲ and ▼ keys, it would be nice if
the user would be alerted to this by the ▼▲ annunciator in the display turning
on. The manual does not mention this behavior, but older editions of the
Programming Examples and Techniques book do (page 34, bottom). It doesn't work
on the actual calculator, at least not on any that I've heard of.
Free42 does turn on the ▼▲ annunciator. Although my general rule is to mimic
the HP-42S as closely as possible, I felt that this was a nice feature and that
it's pretty unlikely to break anything. :-)


-------------------------------------------------------------------------------
[MIN], [MAX], and [FIND]: undocumented HP-42S matrix functions

[MIN] finds the lowest element of the current column, starting at the current
row, of the indexed matrix, and returns the element to X and the row where it
was found to Y; [MAX] is like [MIN] except it finds the highest element; if the
minimum or maximum is not unique (it is found in more than one row), the
highest matching row is returned. [MIN] and [MAX] require the indexed matrix to
be a real matrix, and they do not allow string elements in the column being
searched.

[FIND] locates a specific value, searching the indexed matrix left to right and
top to bottom. The function works as a conditional: when a program is running,
the following instruction is executed if a match is found, and skipped if a
match is not found; when executed interactively, the display shows "Yes" if a
match is found and "No" if not.
Also, if a match is found, I and J are set to point to it.
The indexed matrix may be real or complex, and the search value may be real,
complex, or string; real or string values are only found in real matrices, and
complex values are only found in complex matrices; in other words, 5 is not
considered equal to 5 + 0i -- mathematically speaking this is wrong, but on the
other hand it is consistent with the behavior of the X=Y? and X≠Y? functions.


-------------------------------------------------------------------------------
Differences between the Free42 printer emulation and the HP-42S/82240

Free42 prints programs differently in NORM or TRACE modes: in NORM mode, the
listing is right-justified, and in TRACE mode, the listing is compact (multiple
commands per line). The HP42S does not do this; Free42 "inherited" this
behavior from the HP-82143 printer, which the author remembers fondly. :-)

When the HP-42S has to print a line that is too long to fit on one physical
printer line (i.e., more than 24 characters), it takes no special action.
Whether the printer prints the overflow left- or right-justified remains to be
found out. I should check the 82240 specs to see how it behaves.
Free42 usually prints the overflow left-justified; the only exceptions are PRP
and LIST in NORM mode.
Comments
  • Feature request: Set of commands to simulate the behaviour of the builtin applications like solver and numerical integration

    Feature request: Set of commands to simulate the behaviour of the builtin applications like solver and numerical integration

    I think that it could be interesting to add a set of commands to be able to mimic built in applications like solver and numerical integration. A set of commands to select functions and deal with MVARs to finally run a program based on the selected functions and parameters.

    opened by fmartinp 37
  • Skin Color Shift?

    Skin Color Shift?

    Thank you for a great program!

    Looking through the Windows skins, I like the "auto" part in Nova1_360x640_auto. And I like the keyboard hints of some of the other skins, so I tried to add the hints. The resulting GIF file looks fine in Paint.Net and in Windows Explorer preview, but when loaded into Free42, the colors are completely different, somewhat similar to a hue shift of 180, but not quite:

    image

    Even just loading and saving the Nova1_360x640_auto.gif file produces this effect. Why does this happen? Is there a work-around?

    opened by salvis 22
  • better complex tan()

    better complex tan()

    core_command6.cc use identity: tan(A+B) = (sin(2A) + sin(2B)) / (cos(2A) + cos(2B))

    tan(x+i*y) = (sin(2x) + i * sinh(2y)) / (cos(2x) + cosh(2y))

    With cos() range of -1 to 1, denominator might suffer cancellation errors. Example, for tan(1.57079632679+1.57079632679E-10i)

    Mathematica (34 sig. diigts) = 198259844.2684457351073074341883681 + 6360017400.061800948953381036777052i

    Free42: (lost 20 sig. digits !) = 198259844.2684462500753790941269250 + 6360017400.061817468717674802797319i

    Better formula is tan(A+B) = (sin(A)*cos(A) + cos(B)*sin(B)) / (cos(A)*cos(A) - sin(B)*sin(B))

    tan(x+i*y) = (sin(x)*cos(x) + i * cosh(y)*sinh(y)) / (cos(x)^2 + sinh(y)^2)

    Denominator is now safe from cancellation errors. Divide num, den by cos(x)^2: (with finite-precision, cos(x) ≠ 0, thus will not hit with divide-by-zero issue)

    tan(x+i*y) = (tan(x) + i * cosh(y)*sinh(y)/cos(x)^2) / (1 + sinh(y)^2/cos(x)^2)

    1/cos(x)^2 = 1 + tan(x)^2 cosh(y) = sqrt(1 + sinh(y)^2)

    Simplify with t = tan(x), S = sinh(y), a = S + St^2, b = 1 + Sa

    tan(x+iy) = t/b + i * sqrt(1+SS) * a/b

    If b overflowed, it implied cosh(y) ≈ |sinh(y)|, imaginery part = sign(y) = ±1

    Redo example with new formula, using Free42 Decimal:

    x + iy = 1.57079632679+1.57079632679E-10i t = tan(x) = 204222536562.2478227241769513521222 S = sinh(y) = 1.570796326790000000006459640975002e-10 a = S+Stt = 6551295804822.614830404305805658496 b = 1+Sa = 1030.075138593010014316438138894843

    t/b + i * sqrt(1+S*S) * a/b = 198259844.2684457351073074341883681 + 6360017400.061800948953381036777053i

    opened by achan001 18
  • Pasting numbers in Windows

    Pasting numbers in Windows

    We've talked about the decimal separator and digit grouping before, and I accept your stance on keeping Free42 the same as the HP original.

    In my locale, numbers are formatted as 1'234'567.89, and that's what my Windows settings reflect. However, because HP supports only either the dot and the comma or the comma and the dot for decimal separator and digit grouping, I've chosen to use the more prominent comma as my decimal point some 45 years ago. I work in FIX mode most of the time, and the comma serves as a constant reminder to me that the punctuation is backwards. I've learned to live with that.

    However, when I paste "1'234'567.89" into Free42, what do I get? — I get "1,00"! This is, er, less than ideal.

    Actually, it's a real pain having to paste my number somewhere, remove the quotes, copy and paste it again, and what do I get? — "123.456.789,00"! I have to change my decimal point into a comma, too.

    I understand that this is working exactly as you designed it, but you're not constrained by HP's prior art here, and you could do much better. Here's my proposal:

    1. When you get a string from the clipboard, check the environment for the digit grouping character and remove all of these.
    2. Parse the number as you do now, but interpret the first comma, dot, or any other characters listed on https://en.wikipedia.org/wiki/Decimal_separator as the decimal separator.
    3. When copying a number to the clipboard, format it according to the number format defined in the environment.

    I believe this would make a lot of people happy, and I can't think of any reason why anyone would prefer the current design.

    opened by salvis 15
  • Xcode project for MacOS refers to file that does not exist.

    Xcode project for MacOS refers to file that does not exist.

    Nice project!

    When trying to build for MacOS with Xcode I get this error:

    error: Build input file cannot be found: '/Users/XXXXX/Downloads/free42-master/mac/readtest_lines.cc'

    I fixed it by simply doing

    touch free42-master/mac/readtest_lines.cc

    opened by PaulHaeberli 13
  • Kahan complex acosh

    Kahan complex acosh

    From https://opensource.apple.com/source/Libm/Libm-47.1/complex.c.auto.html Algorithm from https://people.eecs.berkeley.edu/~wkahan/MathSand.pdf, page 36

      real(cacosh(z)) = arcsinh(real(csqrt(cconj(z)-1.0)*csqrt(z+1.0)))
      imag(cacosh(z)) = 2.0*atan(imag(csqrt(z-1.0)/real(csqrt(z+1.0))))
    
    int math_acosh(phloat xre, phloat xim, phloat *yre, phloat *yim) {
       ...
       /* a = sqrt(x + 1) */
       ...
       /* b = sqrt(x - 1) */
       ...
       /* c = x + a * b */
       cre = xre + are * bre - aim * bim;
       cim = xim + are * bim + aim * bre;
    
       /* y = log(c) */
       *yre = log(hypot(cre, cim));     // = asinh(are*bre + aim*bim)
       *yim = atan2(cim, cre);          // = atan(bim/are) * 2
       return ERR_NONE;
    }
    

    With this algorithm, it remove calculations of c = x + a * b, and its errors.

    asinh argument without cancellation errors (sum of terms, both non-negative) This guaranteed yre ≥ 0, regardless of rounding errors.

    atan() cheaper than atan2(), and give more accurate yim. It would be even better if we do complex sqrt (for a, b) directly, without using angles.

    Less code, better accuracy !

    opened by achan001 10
  • FUNC's unexpected behaviour in NSTK mode

    FUNC's unexpected behaviour in NSTK mode

    Hi, I really like big stack mode, but FUNC is not working in the same way as in 4STK mode. I'm not sure if this is a bug or some kind of limitation.

    Here are some test programs, all should have same result in 4STK: Y: 10 X: 25 and respectively in NSTK: 2: 10 1: 25 But only first one (tstN) is behaving same in both modes, all others are unable to restore stack to expected state.

    LBL "tstN"
    CLST
    10
    25
    FUNC 00
    30
    40
    +
    END
    
    LBL "tstX1"
    CLST
    10
    25
    FUNC 00
    50
    +
    END
    
    LBL "tstX2"
    CLST
    10
    25
    FUNC 00
    CLST
    END
    
    LBL "tstX3"
    CLST
    10
    25
    FUNC 00
    +
    END
    
    LBL "tstX4"
    CLST
    10
    25
    FUNC 00
    SQRT
    END
    
    opened by Slasy 10
  • Solver misses sign reversal on simple example

    Solver misses sign reversal on simple example

    I was following the example given p. 116 of the “Example and techniques” manual (solving the function f(x)=x/(x²-6), with initial guesses of 2.3 and 2.7).

    Apparently the original HP-42S would detect the sign reversal (the function has a pole at √6). Free42 instead indicates success (returning a variable value close to √6, with of course a very large function value).

    Depending on how close you aim to be to the original HP-42S solver, this may or may not qualify as a bug.

    opened by svillemot 10
  • [android] auto-rotate doesn't change skin on Android 11

    [android] auto-rotate doesn't change skin on Android 11

    Ever since upgrading from Android 10 to 11, Free42 doesn't switch skins when rotating the screen, instead the portrait skin gets squished to landscape dimensions. This isn't an issue in Android 10.

    Emulator screenshot: image

    Changing the skin manually works, but then the reverse problem happens when switching back to portrait mode.

    Fortunately, it seems like there's an easy fix. According to https://developer.android.com/guide/topics/resources/runtime-changes

    If you want to manually handle orientation changes in your app you must declare the "orientation", "screenSize", and "screenLayout" values in the android:configChanges

    Free42's manifest only specifies android:configChanges="orientation", and changing that to android:configChanges="orientation|screenSize|screenLayout" seems to work for me and restore the expected skin-switching behavior.

    I'm not sure why screenSize and screenLayout are required when Free42Activity's onConfigurationChanged method only cares about orientation, and the docs don't mention any changes between Android 10 or 11.

    opened by aswild 8
  • Feature Request: Publish releases on f-droid.org

    Feature Request: Publish releases on f-droid.org

    f-droid.org is a (popular?) 'free' apk store alternative to google. The convenience of it to users is that new releases can be automatically updated instead of tracking each developer's website and manually side-loading.

    opened by Boruch-Baum 8
  • Radix and Digit Grouping

    Radix and Digit Grouping

    You have a minor error on your https://thomasokken.com/free42/#doc page: "RDX. in the MODES menu" — it's in the DISP menu.

    HP's use of the "other" decimal separator for digit grouping has irritated me for 45 years now, because it's a source of ambiguity. I see that you've denied this request in the past (https://forum.swissmicros.com/viewtopic.php?t=409), but please allow me to add my vote in favor of an option to use the space for digit grouping.

    According to https://en.wikipedia.org/wiki/Decimal_separator#Digit_grouping and https://en.wikipedia.org/wiki/ISO_31-0#Numbers, there is a strong international push towards using the space:

    Numbers consisting of long sequences of digits can be made more readable by separating them into groups, preferably groups of three, separated by a small space. For this reason, ISO 31-0 specifies that such groups of digits should never be separated by a comma or point, as these are reserved for use as the decimal sign.

    If ISO says to not use the comma or point for digit grouping, we're on pretty solid ground for fixing a blunder made by HP half a century ago, not on a "slippery slope". :-)

    opened by salvis 5
A hobby project using Swift protocol and Swift 5.7's new generics to build an iOS Calculator-like calculator.

Calculator A hobby project using Swift protocol and Swift 5.7's new generics to build an iOS Calculator-like calculator. Highlights: You can use Calcu

Kyle 4 Oct 24, 2022
An experimental prototype calculator.

What is NumberPad NumberPad is an experimental prototype to explore how we write, visualize, and manipulate math equations. This post highlights some

Bridger Maxwell 87 Apr 25, 2022
A tip calculator for iOS (in Swift) and Android

Round & Split I needed a tip calculator, so I wrote one. I always round my tips, and when I dine out with a friend, I email them reminders that I owe

Lukhnos Liu 48 Jun 25, 2022
SIP calculator calculates the future value of SIP (Systematic Investment Plan) payments.

SIP calculator calculates the future value of SIP (Systematic Investment Plan) payments. This app is available in the AppStore. Learn more here. #Desc

Tirupati Balan 26 Dec 7, 2022
Tippy is a tip calculator application for iOS.

Pre-work - Tippy Tippy is a tip calculator application for iOS. Submitted by: Shoaib Huq Time spent: 5 hours spent in total User Stories The following

Shoaib Huq 0 Nov 24, 2021
Implementation of LondonAppBrewery's BMI Calculator App

BMI Calculator ?? Our Goal The objective of this tutorial is to look at how we can customise Flutter Widgets to achieve our own beautiful user interfa

Marianne Leal 0 Dec 8, 2021
Basic calculator app for iOS devices using Swift3. Created for learning purpose.

iOS Calculator App Basic calculator app for iOS devices using Swift 4 and Xcode 9. Created for learning purpose. How to use Just download source code

Jogendra 15 Dec 28, 2022
A basic discount calculator app Using Swift

DiscountCalcuator This is a basic discount calculator app I created. Have you ever been out shopping and there is a really awesome sale going on? Well

Alex Diaz 1 Dec 11, 2021
iOS calculator app made without storyboard.

Calculator app Standart iOS calculator app written without storyboard - elements placed only by using code. FUN FACT - you can download it and install

Paweł Brzozowski 1 Dec 21, 2021
Tipculator is a tip calculator application for iOS.

Pre-work - Tipculator Tipculator is a tip calculator application for iOS. Submitted by: Jordan Sukhnandan Time spent: Prework-> 3 hours Additional fea

Jordan Sukhnandan 0 Feb 1, 2022
Splito - Nice and easy-to-use billing and tip calculator with swift

Splito! Nice and easy-to-use billing and tip calculator

Aleksandr Morozov 9 Dec 30, 2022
Bmi calculator app (iOS)

BMI Calculator Our Goal The goal of this tutorial is to learn more about Optionals, solidify your understanding of the MVC design pattern and to intro

null 0 Jan 3, 2022
CodePathPrework - The pre-work assignment for the CodePath program. Involves making a tip calculator using XCode.

Pre-work - Tip Calculator Tip Calculator is a tip calculator application for iOS. Submitted by: David Zhu Time spent: 3 hours spent in total User Stor

null 0 Jan 3, 2022
A clone of the built-in iOS Calculator APP for iPadOS, using SwiftUI

A clone of the built-in iOS Calculator APP for iPadOS, using SwiftUI Yes, it looks exactly the same as the iOS built-in Calculator The UI is implement

Bobby Wang 31 Jan 1, 2023
Recreation of calculator-checklist project in SwiftUI

Calculator Checklist A project created out of curiosity to test the waters of SwiftUI, Apple's new UI Framework. The caculator-checklist concept was o

T. Abbas Khan 278 Nov 17, 2022
BMI-Calculator - An app which calculates the BMI and gives suggestion

BMI-Calculator An app which calculates the BMI and gives suggestion with MVC pat

null 0 Jan 19, 2022
BodyMassIndexCalculator - A multiscreen BMI Calculator app

Body Mass Index Calculator A multiscreen BMI Calculator app Uses UISliders for w

Matt Wong 1 Jan 29, 2022
Stock Average Down Calculator

A calculator to figure out what your new average stock price and future value will be on purchasing of a new stock. Most of the custom code can be found in ViewController.swift

Mykel Agathos 1 Apr 18, 2022
A Windows calculator ported to macOS with SwiftUI interface.

Windows Calculator on Apple A Windows calculator ported to macOS with SwiftUI interface. Standard Programmer Build Clone the project: git clone --recu

Li-Huai (Allan) Lin 4 Dec 31, 2022