Commit graph

2262 commits

Author SHA1 Message Date
Christophe de Dinechin
0c7cef7bc7 library: Equation fixes
Various fixes in equations to avoid errors while parsing them.

Fixes: #1129

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-08-28 01:38:27 +02:00
Christophe de Dinechin
20c127d064 library: Add larger set of equations
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>
2024-08-28 01:38:27 +02:00
Christophe de Dinechin
993f84efb8 complex: Fix parsing error when parsing units
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>
2024-08-28 01:38:27 +02:00
Christophe de Dinechin
fcbb81dcff Release 0.7.15 "Teaching" - Bug fixes notably on iOS
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>
2024-08-25 22:03:42 +02:00
Christophe de Dinechin
97a3252c91 units: Restrict unit expressions further
Only allow exponents with real values, and restrict allowed commands.

Fixes: #1135

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-08-23 14:38:42 +02:00
Christophe de Dinechin
75ac41bbd6 Makefile: Remove unwanted attributes from geneated tar file
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>
2024-08-23 14:00:27 +02:00
Christophe de Dinechin
8a4559e3ac Makefile: Only include help[ file for target
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>
2024-08-23 13:46:20 +02:00
Christophe de Dinechin
1ee54c9662 constants: Fix numerical value for G constant
The G constant had a bad definition with `2•kg` instead of `2*kg`.

Fixes; #1128

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-08-23 11:55:32 +02:00
Christophe de Dinechin
2157a99937 tests: Rename 'M' demo helper to 'D'
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>
2024-08-23 11:55:22 +02:00
Christophe de Dinechin
b3af5db1e1 makefile: Add mv echo for image comparisons
This is simply for convenience while updating tests.

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-08-23 11:55:22 +02:00
Christophe de Dinechin
ce3faed861 files: Close source files before evaluating them
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>
2024-08-23 11:55:22 +02:00
Christophe de Dinechin
9fb4489922 units: Use pi constant in definition of radians unit
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>
2024-08-23 11:55:21 +02:00
Christophe de Dinechin
5686c4c7ef parser: Detect syntax error on (inv(x)) in non-expression mode
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>
2024-08-22 23:10:39 +02:00
Christophe de Dinechin
96a98b6e04 units: Avoid infinite loop for bad unit exponents
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>
2024-08-22 16:10:51 +02:00
Christophe de Dinechin
116e425f3a files: Avoid crash in file_closer if file does not exist
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>
2024-08-22 16:10:51 +02:00
Christophe de Dinechin
2ae5372fb1 tests: Add DMS/HMS operations to math demo
Add a simple demo of basic HMS, date and time operations.

Fixes: #1122

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-08-19 15:15:41 +02:00
Christophe de Dinechin
dee4501d7e tests: Add keyboard shortcuts to launch the demos
F7, F8 and F9 directly invoke the appropriate demos.

Fixes: #1121

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-08-19 14:19:15 +02:00
Christophe de Dinechin
104e4b976c Release 0.7.14 "Kids" - Equation-related bug fixes
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>
2024-08-18 12:14:07 +02:00
Christophe de Dinechin
28ff1800bc ui: Keep a GC pointer in draw_object
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>
2024-08-17 12:19:51 +02:00
Christophe de Dinechin
45241752e6 trigonometrics: Add conversion from non-standard angles
Accept `cos(1/4_turn)` without emiting an `Inconsistent Unit` error.

Fixes: #1114

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-08-16 22:35:57 +02:00
Christophe de Dinechin
cbd165d0f3 equations: Add missing units in some equations
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>
2024-08-16 22:35:57 +02:00
Christophe de Dinechin
3ce815c12e equations: Add explicit radian unit in Eccentric Columns cos
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>
2024-08-16 22:30:56 +02:00
Christophe de Dinechin
aca1c1743f units: Correctly factor out non-integral powers
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>
2024-08-16 22:15:45 +02:00
Christophe de Dinechin
de78d5f572 catalog: Display commands that begin with selection first
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>
2024-08-16 15:29:27 +02:00
Christophe de Dinechin
d7547676d8 debug: Debug on error
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>
2024-08-16 15:29:27 +02:00
Christophe de Dinechin
fe295d03f3 stats: When computing a sum, evaluate the expression on all terms.
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>
2024-08-14 12:00:06 +02:00
Christophe de Dinechin
a742e28af5 graphics: Error out in RGBPattern for negative input
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>
2024-08-14 12:00:06 +02:00
Christophe de Dinechin
7fb1ee40ad ui: Select orange as background color during search
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>
2024-08-14 12:00:05 +02:00
Christophe de Dinechin
fa62f3f275 tests: Add three 30 second demo of DB48X features
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>
2024-08-14 12:00:05 +02:00
Christophe de Dinechin
8027ec8d77 help: Render shift keys correctly in the color version
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>
2024-08-07 18:08:20 +02:00
Christophe de Dinechin
898ca3115c Release 0.7.13 "Murderers" - Solver improvements
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>
2024-08-05 09:10:53 +02:00
Christophe de Dinechin
21d8ea7a5f loops: For loops on lists and arrays
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>
2024-08-05 08:45:06 +02:00
Christophe de Dinechin
e43f1971e7 bignum: Compute correct bignum type for difference
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>
2024-08-02 02:26:17 +02:00
Christophe de Dinechin
4c2306d2a5 48calc.org: Fix mouse click position
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>
2024-08-02 01:32:52 +02:00
Christophe de Dinechin
a62e4425d0 equations: Add missing equations from "Columns and Beams"
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>
2024-08-01 17:48:46 +02:00
Christophe de Dinechin
83d6536626 parser: Deal with negation more "normally", parse -a² correctly
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>
2024-08-01 17:48:46 +02:00
Christophe de Dinechin
a83a6057b7 unit: Set unit::mode while operating on units
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>
2024-08-01 02:49:42 +02:00
Christophe de Dinechin
c6cb72c021 solver: Preserve errors reported by underlying function
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>
2024-08-01 02:49:42 +02:00
Christophe de Dinechin
f24f99984f conditionals: Parse and evaluate IFTE correctly
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>
2024-08-01 01:50:55 +02:00
Christophe de Dinechin
b6b0fa76fe equations: Add Simple Slope equation
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>
2024-07-31 21:00:28 +02:00
Christophe de Dinechin
0aaf12e23e units: The EvalEq command should not evaluate dates
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>
2024-07-31 20:58:57 +02:00
Christophe de Dinechin
fb71fc145f units: Allow ubase to work on expressions
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>
2024-07-31 20:58:57 +02:00
Christophe de Dinechin
6c4900382c menus: Add R→D, D→R, →Polar and →Rectangular
These commands are implemented but not present in `AnglesMenu`.

Fixes: #1090

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-07-31 20:58:57 +02:00
Christophe de Dinechin
1d7ef89cef equations: Add Simple Deflection
From HP50G advanced reference manual page 5-5

Refs #1040

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-07-31 20:58:57 +02:00
Christophe de Dinechin
1856b3c2b0 solver: Do not change unit when storing in a solver variable
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>
2024-07-31 16:22:22 +02:00
Christophe de Dinechin
87a20cfc9e solver: Keep units and constants as-is in equation
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>
2024-07-31 16:11:22 +02:00
Christophe de Dinechin
34b6011980 equations: Add Eccentric Columns
Add Eccentric Columns equations from HP50G Advanced Reference Manual

Refs: #1040

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-07-31 02:26:52 +02:00
Christophe de Dinechin
5e43b5bba8 units: Simplify units that convert to real numbers
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>
2024-07-31 02:26:52 +02:00
Christophe de Dinechin
6699dd64bd solver: Make precision relative to equation sides magnitude
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>
2024-07-31 01:47:02 +02:00
Christophe de Dinechin
59c9d183e5 build: Add BMP files to the distribution
From now on, we should probably only ship the tar files.

Fixes: #1083

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-07-31 01:47:02 +02:00