Add a number of new equations to the equation library, contributed by
Jean Wilson.
Fixes: #1129
Co-authored-by: Jean Wilson <srmjwilson@gmail.com>
Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
When parsing units or expressions with parentheses, turn ERROR into
SKIP to make sure the higher-level selected expression parsing.
Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
This release mostly focuses on issues exposed by the iOS releases.
It's a bug-fixes only release.
***Bug fixes***
* ios: Fix a screen refresh bug delaying the display of computation results
* ios: Increase user-accesssible memory for DB50X to match the DM32
* files: Avoid opening two files when a loaded file contains units/constants
* units: Restrict unit expressions further, e.g. forbid `1_km^s`
* build: Do not add unwanted macOS-specific files in release tar files
* build: Remove irrelevant help file from releae tar file
* constants: Fix numerical value for G constant
* tests: Rename `M` demo helper to `D`, since we use `M` in symbolic tests
* makefile: Add `mv` echo to targets doing image comparison
* units: Use pi constant in definition of radians unit
* parser: Detect syntax error on `(inv(x))` in non-expression mode
* units: Avoid infinite loop for bad unit exponents
* files: Avoid crash in `file_closer` if file does not exist
* tests: Add DMS/HMS operations to math demo
* tests: Add keyboard shortcuts to launch the demos
Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
The tar file we build should not include macos crap such as
```
help/img/._SimpleShear.bmp
tar: Ignoring unknown extended header keyword
'LIBARCHIVE.xattr.com.apple.provenance'
```
Fixes: #1125
Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
When distributing a release, only include the relevant help file,
i.e. DB48X.md for DB48X and DB50X.md for DB50x.
Fixes: #1124
Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
The 'M' name is actually used in a number of other tests, where we
expect a symbolic result and get a bug instead.
Renaming to 'D' ensures we don't disrupt those tests if we run them
after a demo.
Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
Since source file evaluation can involve units, constants, etc, we
need to make sure that the file is closed before evaluating it.
Fixes: #1137
Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
The `r` unit is now defined as a function of `pi`.
As a side effect, fix parsing of expressions in units, allowing `inv`
to parse correctly in the definition of radians.
Fixes: #1136
Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
When we parse `(...` in non-expression mode, this is supposed to be a
complex number. If what we parse is not a complex number, then this
should be a syntax error.
Fixes: #1134
Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
If we have a unit expression with a non-numeric exponent, as seen in
bug #1128 where the unit expression parsed as `s^(2*kg)`, we may end
up with an infinite loop trying to factor out the term.
Add two independent fixes to address the problem:
1/ Check if we are making forward progress. If the resulting
expression is the same as before, just stop evaluating the
expression.
2/ In case the heuristic would not work, check if the EXIT key was
pressed by calling `program::interrupted()`.
Fixes: #1133
Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
On simulator, `ftell` crashes if the file was not opened correctly,
so we get a crash in the constructor.
Fixes: #1130
Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
This release fixes a number of issues that were discovered primarily
through the Columns and Beams equations.
**Features**
* trigonometrics: Add conversion from non-standard angles, so that
`cos(1_turn)` gives the correct result.
* debug: Debug on error with `DebugOnError` and `KillOnError`
settings. This makes it easier to debug an RPL program, by making it
possible to single-step around the instruction that generated the
error.
* tests: Add three 30 second demo of DB48X features. These are to
generate marketing videos for the iPhone version on the Apple
store (to be done).
**Bug fixes**
* ui: Keep a GC pointer in `draw_object` to avoid a memory crash
* equations: Add missing units in some equations, e.g. `I` and `A` in
second equation of Coilumns and Beams
* equations: Add explicit `radian` unit in Eccentric Columns `cos`,
which ensures we get the correct result from the HP50G manual even
when in Degrees mode.
* units: Correctly factor out non-integral powers, so that we can
compute `1/sqrt(epsilon_0*mu_0)` and get the correct result.
* catalog: Display commands that begin with selection first, so that
`FORE` shows `Foreground` before `AlphaForeground`.
* stats: When computing a sum, evaluate the expression on all
terms. The result for `Variance` with single variables was wrong
because the first term was computed incorrectly due to a misguided
optimization.
* graphics: Error out in `RGBPattern` for negative input. The negative
values were generating an error, but it was not reported, so the next
command was likely to report it.
* help: Render shift keys correctly in the color version. The bitmap
was interpreted as containing color data. Colorize it instead.
**Improvements**
* ui: Select orange as background color during search. The previous
setting of showing seardch using white foreground on a white
background was probably pushing the notion of "blind search" a bit
too far.
Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
The `obj` pointer in `user_interface::draw_object` was not a GC pointer, but
there is a `do...while` loop calling `obj->graph` that may cause a garbage
collection, causing the input `obj` to be bogus.
Fixes: #1115
Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
There is no unit for some of the equations in the Columns and Beams
category. Notably, some equations are missing the units for `A` and
`I. Adding them back to avoid `Inconsistent units` error when the
variables are not already give a value with a unit (which was the case
from the easlier tests in the test suite).
Fixes: #1113
Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
The `cos` expression in the Eccentric Columns equation should explicitly have an
argument in radians so that it gives the correct result even when in Degrees
mode.
Fixes: #1112
Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
When we evaluate an expression like `1/√(ε₀·µ₀)`, we compute the
square root of unit `F*H`. Unit `F*H` evaluates as `s^2`, so this
ends up with `s`.
This requires evaluating `F^(1/2)*H^(1/2)`, which needs unit mode
flags (`unit::mode` and `unit::factoring`) to be correctly set along
the way, notably while computing powers.
With this, evaluating `'1/√(ε₀·µ₀)' →Num` gives the correct, albeit
unsimplified result `299792458_m/(F^(1/2)*H^(1/2))`. This seems
consistent with the way the HP50G does it. Using `UBase` gives the
correct simplified result `299792458_m/s`.
Fixes: #1110
Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
When selecting `FORE` in the catalog, show `Foreground` first, before
all other commands that contain `Foreground` (there are many settings
with that name).
Fixes: #1106
Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
When we reach an error during program execution, automatically enter
debugging mode and enable the debug menu.
This is controlled by the `DebugOnError` setting, which is set by
default (the opposite is `KillOnError`)
Fixes: #1109
Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
The `total` internal function performs a sum of terms.
The code was optimizing away the sum to zero for the first term, but
as a result ended up not evaluating the term. So the first term in the
sum for the variance was evaluated as `d` instread if `(d-avg)^2`.
Fixes: #1103
Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
Both `RGBPattern` and `GrayPattern` would emit a `Bad argument value`
for negative input, but not error out, so the next command could
report it incorrectly.
Fixes: #1108
Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
The setting was not defined, so we had white as foreground and
background, which made the selection hard to read.
Fixes: #1107
Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
Separated the demo in three sections of 30 seconds each:
- Basics of RPL and user interface (RPL, function keys, online help, catalog,
unicode, text editor)
- Mathematics (complex, vector, matrix, symbolic, based)
- Programming
Fixes: #1104
Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
When rendering the shift keys in color, we need to render a colorized
bitmap.
Fixes: #1100
Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
This releases focuses on improvements to the solver, with the completion of the
Columns and Beams section from the HP50G equation library.
**Features**
* equations: Add remaining equations from "Columns and Beams"
* loops: For loops on lists and arrays
* menus: Add `R→D`, `D→R`, `→Polar` and `→Rectangular`
* menus: Automatically select tools menu for library equations
* units: Allow `ubase` to work on expressions
* units: Graphic rendering of units
**Bug fixes**
* 48calc.org: Fix mouse click position
* `#ABC #DEF -` now correctly produces a based number with >64-bit wordsize
* conditionals: Parse and evaluate `IFTE` correctly
* equations: Fix Elastic Buckling
* files: Avoid crash in `file_closer` if file was not open
* istack: Enable Swap feature on top two levels
* menu: Update SolvingMenu when updating VariablesMenu
* parser: Deal with negation more "normally", parse `-a²` correctly
* solver: Compute units correctly for inputs
* solver: Do not change unit when storing in a solver variable
* solver: Emit correct error message in `EvalEq` if missing variables
* solver: Preserve errors reported by underlying function
* units: Do not evaluate/render units with names
* units: No longer read variables `m` and `s` while processing `1_m/s`
* units: Simplify units that convert to real numbers
**Improvements**
* Update .gitignore
* build: Add BMP files to the distribution
* complex: Optimize exit conditions for parentheses
* solver: Add test for equation library
* solver: Add tests for solving with units
* solver: Improve behaviour of `EvalEq`
* solver: Keep units and constants as-is in equation
* solver: Make precision relative to equation sides magnitude
* stack: Show vectors vertically by default
* ui: Do not persistently hide stack with current equation
* units: Keep power integral, i.e. avoid getting `1_m^2.0/s`
* units: Strip tags from unit conversion functions
* units: The `EvalEq` command should not evaluate dates
* wasm: Add logos to the repository
Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
Allow `for next` and `start next` to operate with a list as input.
For example, `{ 1 3 "ABC" } for i i 2 * 1 + next` pushes
`3`, `7` and `"ABCABC1"` on the stack.
This is an extension compared to classic RPL.
Fixes: #1079
Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
When we have a wordsize of 64 or more, we need to select the same
bignum type for the difference as the input.
Fixes: #1097
Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
Fix handling of mouse click position.
The coordinates were computed relative to the wrong dimensions, so the
buttons were all the more unreliable the more they were at the bottom
and to the right.
Fixes: #1096
Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
Add the missing equations from "Columns and Beams" section of the
HP50G advanced reference manual.
Notice that some of the descriptions are incorrect in the manual, and
that the correct equations had to be fetched from the HP50G itself.
Foe example, the `Simple Moment` example defines `c`, which is not set
in the documented equation. The actual equation contains `IFTE`
expressions, which require the fix for #1093 to work.
Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
We were treating negation in a special way in the expression parser.
As a result, `-a²` was parsed as `(-a)²` instead of `-(a²)`.
Treat negation like a normal prefix, generating an object, which makes
it possible to deal with precedence the right way.
Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
When we multiply or divide unit objects, or raise a unit object to
some power, we don't want to evaluate variables in the unit.
For example, if we have `1_N*m 2_m *`, the result should not depend on
the value of variable `m`.
Fixes: #1095
Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
If the called function errors out, report that error instead of hiding
it behind `Invalid function` error.
Fixes: #1094
Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
The `IFTE` is special in that it does not evaluate its arguments ahead
of time. For example `'IFTE(1;0;ln(0))'` should not result in an error
because of the `ln(0)` evaluation.
Fixes: #1093
Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
Add the equation for Simple Slope from page 5-5/5-6 of the HP50G
advanced reference manual.
Refs: #1040
Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
The date differences evaluation is expensive, so we should avoid doing
it in `EvalEq`.
Fixes: #1092
Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
When we have an expression, it is useful to be able to convert all
values in it to their unit base.
Fixes: #1091
Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
When storing in a solver variable, we need to check that units are
compatible, but we should not change the unit selected by the user.
For example, the Simple Deflection equations example in the HP50G
advanced reference manual are given in obsolete units. We want the
units to remain as is, since it's the user's preference.
Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
Now that we render units in variables correctly, do not remove units
and equations before solving. Instead, evaluate with units and
equations. This is a bit slower, but more precise.
Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
When we are given a value like `1_cm/in`, it is OK to pass it as input
to the `sin` function or similar.
Fixes: #1089
Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
When we have an actual equation in the solver, e.g. `L=R`, then we can
make the epsilon of the solver relative to `L` or `R`.
This allows equations with large values for `L` and `R`, like the
Elastic Buckling examples given, to solve correctly (i.e. without a
`Sign reversal` error message) with the default settings.
Fixes: #1088
Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>