Commit graph

2179 commits

Author SHA1 Message Date
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
Christophe de Dinechin
631fa8f6f3 units: Keep power integral
When we compute powers for units with numerical results on, we may end
up with decimal powers in units for no reason.

Spotted by displaying the result of an `EvalEq` with `FIX 2`.

Fixes: #1086

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-07-30 23:15:31 +02:00
Christophe de Dinechin
4ecde93aaa menu: Update SolvingMenu when updating VariablesMenu
If we change directories, variables, etc, update the solving menu

Fixes: #1085

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-07-30 23:15:30 +02:00
Christophe de Dinechin
5e1b01f8d5 units: Graphic rendering of units
This allows us to have nice-looking exponents in units

Fixes: #1082

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-07-30 23:15:30 +02:00
Christophe de Dinechin
e22d4bbbb8 complex: Optimize exit conditions for parentheses
When parsing an expression that contains parenthese, which could be
interpreted as a complex number, check if this is indeed a complex
number or if this is just a real number.

Fixes: #1084

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-07-30 23:15:30 +02:00
Christophe de Dinechin
cad63dc2c7 solver: Add test for Elastic Buckling equations
Test the values from example in teh HP50G advanced reference manual.

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-07-30 13:36:50 +02:00
Christophe de Dinechin
84cc30a81d solver: Add tests for testing with units
Add test to check that we correctly take the units from

Tests: #1049

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-07-30 11:44:24 +02:00
Christophe de Dinechin
dc1845ea99 istack: Enable Swap feature on top two levels
Fix an off-by-one in the check for end of stack in the interactive
stack editor, so that we can swap the last two levels.

Fixes: #1067

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-07-30 11:44:24 +02:00
Christophe de Dinechin
a918817b12 solver: Emit correct error message in EvalEq if missing variables
We need to make sure that we have a chance to evaluate correctly
before actually evaluating each side.

Fixes: #1078

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-07-30 11:44:24 +02:00
Christophe de Dinechin
d9a58af96a ui: Do not persistently hide stack with current equation
Add support for a "transient object" to be shown for context.
This object will be hidden the next time the stack is redrawn.

That way, we only see the equation when it's useful.

Fixes: #1077

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-07-30 11:44:24 +02:00
Christophe de Dinechin
cbd5386248 units: Strip tags from unit conversion functions
The solver and other operations return tagged objects.
It's practical that conversion functions accept to operate on them.

Fixes: #1076

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-07-30 11:44:24 +02:00
Christophe de Dinechin
622a378186 solver: Compute units correctly for inputs
When we are given inputs that have units, make sure that we convert
them to the proper units before solving.

Fixes: #1075

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-07-30 11:44:24 +02:00
Christophe de Dinechin
b56331befa solver: Improve behaviour of EvalEq
Now, For an expression like `Expr1=Expr2`, the result is given as
another equation `Left=Right+Delta`, which is a much more readable way
to present the result.

Fixes: #1074

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-07-30 11:44:24 +02:00
Christophe de Dinechin
f87663360b equations: Fix Elastic Buckling
The constant in two of the equation is π², not just π.

Fixes: #1073

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-07-30 11:44:24 +02:00
Christophe de Dinechin
acc1cf4f41 units: Do not evaluate/render units with names
If an expression contains something like `P_m`, it indicates that `P`
is a variable with a default unit of `m`. It does not mean that we
should evaluate `P` and apply `m` as a unit afterwards.

So when we have a variable name like that:

- Skip unit application during evaluation
- Skip unit rendering in text and graph mode, unless editing

Fixes: #1075

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-07-30 11:44:23 +02:00
Christophe de Dinechin
1ae02dda1e files: Avoid crash in file_closer if file was not open
It is legitimate for the `file_closer` to be used on a file that could
not open (e.g. the file does not exist).

The `file_closer` must avoid trying to get the position or reopening
the file in that case.

Fixes: #1071

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-07-30 11:43:05 +02:00
Christophe de Dinechin
6ebda6ef3c Update .gitignore
Add generated files under `wasm/` and `help/`

Fixes: #1072

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-07-30 11:43:05 +02:00
Christophe de Dinechin
737fd700e4 wasm: Add logos to the repository
The logos shown on the WASM web site should be put in repository

Fixes: #1070

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-07-30 11:43:05 +02:00
Christophe de Dinechin
b31e6d3b8e stack: Show vectors vertically by default
In practice, it's more useful to have vectors of values show
vertically by default. This is notably true for the results of
`EvalEq` when there is a left, right and diff result.

Fixes: #1069

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-07-30 11:43:04 +02:00
Christophe de Dinechin
c1293a74f7 menus: Automatically select tools menu for library equations
Select the solver menu when we have a library equation, as it's the
most appropriate tool for that type of object.

Fixes: #1068

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-07-29 23:01:04 +02:00
Christophe de Dinechin
e4ff20a949 Release 0.7.12 "Multiply" - Multiple equations
This release focuses on the equation solver, notably in interaction
with the equation library. The goal is to get one step closer to the
equation library in the HP50G, including the ability to have graphical
illustration and multiple equations.

**Features**

* doc: Add documentation for the equation library
* doc: Add images from HP50G equation library (to be used later)
* doc: Some help for the elastic buckling equations.
* equations: Accept lists of equations in library
* help: Add documentation for the various constants
* help: Do not exit help when opening URLs or missing topics
* lists: Add a setting to evaluate list as programs
* menu: Add menu entries for solver imprecision and iterations
* solver: Add support for multiple equation solving
* ui: Add settings to hide/show empty menus and clear menu on EXIT
* units: Add flow units (per user request) in Fluid section of units

**Bug fixes**

* blitter: Adjust the right margin
* blitter: Base horizontal adjust on scanline, not width
* characters: Display correct content for built-in menus
* constants: Close current file while parsing values
* constants: Update some outdated values
* doc: Show help for equations and constants
* help: Do not try to load PNG images
* rewrites: Avoid contradictory rules when reordering constants
* solver: Work correctly with units (when in variables but not equation)

**Improvements**

* build: Shorten the size of the version abbrev
* config: Use config files only for user configuration
* doc: Record performance data about unit conversion
* help: Avoid slowing down when scrolling through pages of help
* help: Record position for history even without a `\n`
* simulator: Add tweak to show RPL object details
* tests: Increase wait time for tests with blinking cursor
* units: Do not simplify while in unit mode

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-07-29 01:45:54 +02:00
Christophe de Dinechin
b8b2fad6e8 units: Add flow units
In order to save space, moved all fluid-related units to the `Fluids`
menu.

Fixes: #1060

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-07-29 01:31:22 +02:00
Christophe de Dinechin
fc1dace26d documentation: Show the correct index for constants and equations
For constant and equations menus, match the index in the help file.

Fixes: #1039
Fixes: #1048

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-07-29 00:39:48 +02:00
Christophe de Dinechin
0f51b08e66 doc: Add images from HP50G equation library
Grabbed images from the HP50G advanced reference manual and converted
them to BMP format so that we can show them on DB48X in the help file.

Fixes: #1034

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-07-28 23:58:08 +02:00
Christophe de Dinechin
024fc5d713 doc: Some help for the elastic buckling equations.
Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-07-28 17:42:54 +02:00
Christophe de Dinechin
5a9e9e0491 equations: Accept lists of equations in library
The HP50G equation library contains equations list, e.g. the
Elastic Buckling set of 4 equations.

Make sure that NextEq and the solver behave correctly with those.

Fixes: #1063

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-07-28 17:40:27 +02:00
Christophe de Dinechin
e04a6ba46c constants: Close current file while parsing values
Parsing the values may require opening another file (units/ constants)
Close it before trying to parse anything.

Fixes: #1062

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-07-28 17:18:37 +02:00
Christophe de Dinechin
85b9be68c8 solver: Add support for multiple equation solving
Add the possibility for the solver to contain a list of equations.
The `NextEq` command rotates the equation list.

Add the `EvalEq` command to evaluate the equation.

Add `EvalEq` and `NextEq` to the solving menu.

Fixes: #1050

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-07-28 16:31:57 +02:00
Christophe de Dinechin
4ddbd8e862 simulator: Add tweak to show RPL object details
Showing the address, type and size of RPL objects is not often useful.
It is generally sufficient to just show the object rendering.

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-07-28 14:20:54 +02:00
Christophe de Dinechin
c736e6a388 doc: Record performance data about unit conversion
Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-07-28 14:14:04 +02:00
Christophe de Dinechin
650000a42d solver: Process units when not given in equation
Deal with units correctly in the solver when they are not supplied in
the equation itself. For example, for equation `'A^2+B^2=C^2'`,
process units correctly if `A=10_m`, `B=85_ft` and `C=1_cm`.

When solving for `C` in the above case, this gives a result in `cm`.

Fixes: #1049
Fixes: #1056

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-07-28 00:50:37 +02:00
Christophe de Dinechin
c5151f8ce8 menu: Add menu entries for solver imprecision and iterations
Add menu labels and entries for `SolverImprecision` and
`SolverIterations` settings.

Fixes: #1058

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-07-28 00:47:39 +02:00
Christophe de Dinechin
6b24aa4be6 units: Do not simplify while in unit mode
In order to accelerate conversions, do not run expression
simplifications while in unit mode. There is a dedicated factoring
step for units, so simplifications do not help much.

Fixes: #1055

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-07-27 17:34:02 +02:00
Christophe de Dinechin
d64fdb3452 config: Use config files only for user configuration
Switch to using the built-in data files by default, and extending them
with teh configuration file.

The `ShowBuiltinConstants`, `ShowBuiltinCharacters` and
`ShowBuiltinUnits` are not on by default. The size of the
corresponding `config/*.csv` files are reduced to a really simple
example.

Fixes: #1052

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-07-27 17:34:02 +02:00