Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

why does the cube root of -8 = NaN? #635

Closed
yeled opened this issue Dec 6, 2023 · 4 comments
Closed

why does the cube root of -8 = NaN? #635

yeled opened this issue Dec 6, 2023 · 4 comments
Labels
bug Something isn't working done Issues that are done on dev (will be in next release) user Reported by an actual user, yay!

Comments

@yeled
Copy link

yeled commented Dec 6, 2023

I was reading https://forum.swissmicros.com/viewtopic.php?f=17&t=2820 and tried the cube root of -8 on a DM32, DM42, C47 and then I tried it on the DB48X (on a DM32)

All of them give either -2 or an imaginary number.

Image

-8
3
1/x

(ignore my mislabled stickers)

@c3d
Copy link
Owner

c3d commented Dec 11, 2023

The NaN result is a result of not catching numerical errors correctly for binary operations. You should get an Argument outside domain error.

I filed a separate bug on this specific problem (#639)

@c3d c3d added bug Something isn't working user Reported by an actual user, yay! labels Dec 11, 2023
@c3d
Copy link
Owner

c3d commented Dec 11, 2023

Please note that there is a specific CBRT function that computes the cube root, and will give you the -2 result. I know that this is not what you were asking, but it's worth pointing out.

@c3d
Copy link
Owner

c3d commented Dec 11, 2023

I was reading https://forum.swissmicros.com/viewtopic.php?f=17&t=2820 and
tried the cube root of -8 on a DM32, DM42, C47 and then I tried it on the
DB48X (on a DM32)

All of them give either -2 or an imaginary number.

Just curious, have you found a calculator that actually returns -2 for (-8)^(1/3)?

HP41: Data error
HP15C: Error 0
HP48: Complex number (principal solution)
HP50: Complex number.

It seems to me like Thomas Okken's answer in that thread is correct: -8^(1/3) is generally understood in terms of exp and log. With a fraction type, we could probably correctly define the expression a^(b/c), though. Let me think about that.

@yeled
Copy link
Author

yeled commented Dec 11, 2023

in my collection:

TI Galaxy 67: -2
C47: -2

@c3d c3d added the done Issues that are done on dev (will be in next release) label Dec 20, 2023
c3d added a commit that referenced this issue Dec 24, 2023
When we have an arithmetic operation that fails, e.g `(-8)^0.3`,
the Intel decimal library reports a `NaN`, and we must convert that
into an error.

Fixes: #639
Fixes: #635

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
c3d added a commit that referenced this issue Dec 25, 2023
This release was a bit longer in coming than earlier ones, because we are about
to reach the limits of what can fit on a DM42. This release uses 711228 bytes
out of the 716800 (99.2%).

Without the Intel Decimal Library code, we use only 282980 bytes. This means
that the Intel Decimal Library code uses 60.2% of the total code space. Being
able to move further requires a rather radical rethinking of the project, where
we replace the Intel Decimal Library with size-optimized decimal code.

As a result, release 0.5.2 will be the last one using the Intel Decimal Library,
and is release in parallel with 0.6.0, which switches to a table-free and
variable-precisions implementation of decimal code that uses much less code
space. The two releases should otherwise be functionally identical

**New features**

* Shift and rotate instructions (#622)
* Add `CompatibleTypes` and `DetsailedTypes` setting to control `Type` results
* Recognize HP-compatible negative values for flags, e.g. `-64 SF` (#625)
* Add settings to control multiline result and stack display (#634)

**Bug fixes**

* Truncate to `WordSize` the small results of binary operations (#624)
* Fix day-of-week shortcut in simulator
* Avoid double-evaluation of immediate commands when there is no help
* Generate an error when selecting base 1 (#628)
* Avoid `Number too big` error on based nunbers
* Correctly garbage-collect menu entries (#630)
* Select default settings that allow solver to find solutions (#627)
* Fix display of decimal numbers (broken by multi-line display)
* Fix rendering of menu entries for `Fix`, `Std`, etc
* Detect non-finite results in arithmetic, e.g. `(-8)^0.3`m (#635, #639)
* Fix range-checking for `Dig` to allow `-1` value
* Accept large values for `Fix`, `Sci` and `Eng` (for variable precision)
* Restore missing last entry in built-in units menu (#638)
* Accept `Hz` and non-primary units as input for `ConvertToUnitPrefix` (#640)
* Fix LEB128 encoding for signed value 64 and similar (#642)
* Do not parse `IfThenElse` as a command
* Do not consider `E` as a digit in decimal numbers (#643)
* Do not parse `min` as a function in units, but as minute (#644)

**Improvements**

* Add `OnesComplement` flag for binary operation (not used yet)
* Add `ComplexResults` (-103) flag (not used yet)
* Accept negative values for `B→R` (according to `WordSize`)
* Add documentation for `STO` and `RCL` accessing flash storage
* Mention `True` and `False` in documentation
* Rename `MaxBigNumBits` to `MaxNumberBits`
* Return HP-compatible values from `Type` function
* Minor optimization of flags implementation
* Catalog auto-completion now suggests all possible spellings (#626)
* Add aliases for `CubeRoot` and `Hypothenuse`
* Align based number promotion rules to HP calculators (#629)
* Expand the range of garbage collector integrity check on simulator
* Show command according to preferences in error messages (#633)
* Avoid crash in `debug_printf` if used before font initialization
* Update performance data in documentation
* Add ability to disable any reference to Intel Decimal Floating-point library
* Simplify C++ notations for safe pointers (`+x` and `operartor bool()`)
* Fix link to old `db48x` project in `README.md`

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
c3d added a commit that referenced this issue Dec 25, 2023
This release was a bit longer in coming than earlier ones, because we are about
to reach the limits of what can fit on a DM42. This release uses 711228 bytes
out of the 716800 (99.2%).

Without the Intel Decimal Library code, we use only 282980 bytes. This means
that the Intel Decimal Library code uses 60.2% of the total code space. Being
able to move further requires a rather radical rethinking of the project, where
we replace the Intel Decimal Library with size-optimized decimal code.

As a result, release 0.5.2 will be the last one using the Intel Decimal Library,
and is release in parallel with 0.6.0, which switches to a table-free and
variable-precisions implementation of decimal code that uses much less code
space. The two releases should otherwise be functionally identical

**New features**

* Shift and rotate instructions (#622)
* Add `CompatibleTypes` and `DetsailedTypes` setting to control `Type` results
* Recognize HP-compatible negative values for flags, e.g. `-64 SF` (#625)
* Add settings to control multiline result and stack display (#634)

**Bug fixes**

* Truncate to `WordSize` the small results of binary operations (#624)
* Fix day-of-week shortcut in simulator
* Avoid double-evaluation of immediate commands when there is no help
* Generate an error when selecting base 1 (#628)
* Avoid `Number too big` error on based nunbers
* Correctly garbage-collect menu entries (#630)
* Select default settings that allow solver to find solutions (#627)
* Fix display of decimal numbers (broken by multi-line display)
* Fix rendering of menu entries for `Fix`, `Std`, etc
* Detect non-finite results in arithmetic, e.g. `(-8)^0.3`m (#635, #639)
* Fix range-checking for `Dig` to allow `-1` value
* Accept large values for `Fix`, `Sci` and `Eng` (for variable precision)
* Restore missing last entry in built-in units menu (#638)
* Accept `Hz` and non-primary units as input for `ConvertToUnitPrefix` (#640)
* Fix LEB128 encoding for signed value 64 and similar (#642)
* Do not parse `IfThenElse` as a command
* Do not consider `E` as a digit in decimal numbers (#643)
* Do not parse `min` as a function in units, but as minute (#644)

**Improvements**

* Add `OnesComplement` flag for binary operation (not used yet)
* Add `ComplexResults` (-103) flag (not used yet)
* Accept negative values for `B→R` (according to `WordSize`)
* Add documentation for `STO` and `RCL` accessing flash storage
* Mention `True` and `False` in documentation
* Rename `MaxBigNumBits` to `MaxNumberBits`
* Return HP-compatible values from `Type` function
* Minor optimization of flags implementation
* Catalog auto-completion now suggests all possible spellings (#626)
* Add aliases for `CubeRoot` and `Hypothenuse`
* Align based number promotion rules to HP calculators (#629)
* Expand the range of garbage collector integrity check on simulator
* Show command according to preferences in error messages (#633)
* Avoid crash in `debug_printf` if used before font initialization
* Update performance data in documentation
* Add ability to disable any reference to Intel Decimal Floating-point library
* Simplify C++ notations for safe pointers (`+x` and `operartor bool()`)
* Fix link to old `db48x` project in `README.md`

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
@c3d c3d closed this as completed in d6496c9 Dec 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working done Issues that are done on dev (will be in next release) user Reported by an actual user, yay!
Projects
None yet
Development

No branches or pull requests

2 participants