Though, having said all this, it makes one wonder what OP's actual use case was. I don't think that was ever explained. I mean, what I am saying is that the simplest solution to OP's problem is just to re-parenthesize his expression:As you already imagined, this will not solve my problem.
expect 1.2> expr -8 ** (1.0/3)
Error: domain error: argument not in valid range
expect 1.3> expr -(8 ** (1.0/3))
Result: -2.0
expect 1.4>
Voila! Problem solved.
Am 04.12.2025 um 13:37 schrieb Kenny McCormack:
Though, having said all this, it makes one wonder what OP's actual use case >> was. I don't think that was ever explained. I mean, what I am saying isAs you already imagined, this will not solve my problem.
that the simplest solution to OP's problem is just to re-parenthesize his
expression:
expect 1.2> expr -8 ** (1.0/3)
Error: domain error: argument not in valid range
expect 1.3> expr -(8 ** (1.0/3))
Result: -2.0
expect 1.4>
Voila! Problem solved.
I fixed this in my code by if/else and asking about the sign of the base.
In general Tcl has no standard function to correctly compute $a**(1.0/$b).
I think this needs to be solved.
Note: I don't know enough TCL to know the actual names/syntax for what I am proposing, but it seems you could do something like:
sgn(x)*(abs(x) ** (1.0/n))
In article <10gs0f8$14a4k$[email protected]>,
meshparts <[email protected]> wrote:
Am 04.12.2025 um 13:37 schrieb Kenny McCormack:
Though, having said all this, it makes one wonder what OP's actual use case >>> was. I don't think that was ever explained. I mean, what I am saying is >>> that the simplest solution to OP's problem is just to re-parenthesize his >>> expression:As you already imagined, this will not solve my problem.
expect 1.2> expr -8 ** (1.0/3)
Error: domain error: argument not in valid range
expect 1.3> expr -(8 ** (1.0/3))
Result: -2.0
expect 1.4>
Voila! Problem solved.
I fixed this in my code by if/else and asking about the sign of the base.
Note: I don't know enough TCL to know the actual names/syntax for what I am proposing, but it seems you could do something like:
sgn(x)*(abs(x) ** (1.0/n))
Editorial comment: IMHO, sgn() is an often useful function that should be present in our toolkits. It is sad that most such toolkits omit it.
In general Tcl has no standard function to correctly compute $a**(1.0/$b). >> I think this needs to be solved.
Agreed.
Am 04.12.2025 um 14:05 schrieb Kenny McCormack:
In article <10gs0f8$14a4k$[email protected]>,Christian Gollwitzer already proposed a user defined function to solve
meshparts <[email protected]> wrote:
Am 04.12.2025 um 13:37 schrieb Kenny McCormack:
Though, having said all this, it makes one wonder what OP's actualAs you already imagined, this will not solve my problem.
use case
was. I don't think that was ever explained. I mean, what I am
saying is
that the simplest solution to OP's problem is just to re-
parenthesize his
expression:
expect 1.2> expr -8 ** (1.0/3)
Error: domain error: argument not in valid range
expect 1.3> expr -(8 ** (1.0/3))
Result: -2.0
expect 1.4>
Voila! Problem solved.
I fixed this in my code by if/else and asking about the sign of the
base.
Note: I don't know enough TCL to know the actual names/syntax for what
I am
proposing, but it seems you could do something like:
sgn(x)*(abs(x) ** (1.0/n))
Editorial comment: IMHO, sgn() is an often useful function that should be
present in our toolkits. It is sad that most such toolkits omit it.
In general Tcl has no standard function to correctly compute
$a**(1.0/$b).
I think this needs to be solved.
Agreed.
this: nthroot
But this function should be standard in Tcl.
We need a TCL ticket for this.I could write an email to tcl-core, would that suffice?
Any voluntears ?
On 12/3/25 19:10, Tristan Wibberley wrote:
On 01/12/2025 14:57, Eric Hassold wrote:
... at system level, since calculating pow(-8.0,1.0/3.0) operates on
floating point numbers, the exponent is not known anymore to be a
rational number when pow() is calculated.
Are there irrational floating-point numbers? I thought every
floating-point number (obviously not NaNs and infs) was a rational.
In your example the exponent is a rational number even if it's:
3333333333333333/10000000000000000
as it appears to be on my local Tcl version:
expr {1.0/3.0}
0.3333333333333333
Sure
every IEEE754 number is de facto a rational number:
value = (Signbit ? -1 : 1) * (1 + Mantissa) * 2^(Exponent - 1023)--
But that rational number is not (necessarily) equal to the initial
rational number, and the parity of its numerator/denominator is not preserved.
Let's take this 1.0/3.0. The calculated IEEE754 number is:
(0, 01111111101, 0101010101010101010101010101010101010101010101010101) that is:
(1 + (0x5555555555555 / 2**52)) * 2^(1021 - 1023)
or, in pure fractional form:
0x15555555555555 / (2**54)
and, if converted back to decimal, is exactly:
0.333333333333333314829616256247390992939472198486328125
What about 1.0/6.0? well, very similar, we end up with:
0x15555555555555 / (2**55)
i.e., in decimal:
0.1666666666666666574148081281236954964697360992431640625
Then the issue is clear. Those two numbers have same parity (odd
numerator, even denominator), not correlated with the parity of their original fractional form (odd for 1/3, even for 1/6). So if trying to evaluate say pow(-8.0, 1.0/3.0) and pow(-64, 1.0/6.0), it is impossible
to determine, from the IEEE754-encoded "fractional form", that the
former may return -2 but the latter should fail.
| Sysop: | DaiTengu |
|---|---|
| Location: | Appleton, WI |
| Users: | 1,114 |
| Nodes: | 10 (0 / 10) |
| Uptime: | 492512:26:19 |
| Calls: | 14,267 |
| Calls today: | 3 |
| Files: | 186,320 |
| D/L today: |
26,345 files (8,540M bytes) |
| Messages: | 2,518,406 |