Why is there not a ipow version of pow?
ipow would return an int instead of a double.-a Or a long long int.
Am 11.08.2026 um 10:01 schrieb Lynn McGuire:
Why is there not a ipow version of pow?
ipow would return an int instead of a double.-a Or a long long int.
Integer multiplies have nearly the same cost as floating point multi-
plies.
Have you done any actual measurements?
In fact it is slower than with floats since conversion between ints and floats is needed.
On 11/08/2026 12:11, Bonita Montero wrote:
Am 11.08.2026 um 10:01 schrieb Lynn McGuire:
Why is there not a ipow version of pow?
ipow would return an int instead of a double.-a Or a long long int.
Integer multiplies have nearly the same cost as floating point multi-
plies.
Have you done any actual measurements?
My language has an "**" operator which is overloaded for ints and floats.
Doing a**b, which uses a special recursive routine for integers, is 5
times as fast as for floats where it calls out to 'pow()' inside msvcrt
C library.
(This was for a=4, b=3; it will likely vary for integers depending on b,
but b is unlikely to be large, as the results would overflow anyway.
However for 2**63 - I'm using 64 bits - the integer version was still
twice as fast.)
With C, you are dependent on how well a compiler may optimise it. But an expression like c = pow(a, b), where a/b/c are all ints, still seemed to call pow() even using gcc-O3.
In fact it is slower than with floats since conversion between ints and floats is needed.
I did run the numbers. I wasn't wrong but also not totally right.
The result of the difference between integer and fp-multiplies
is nearly zero:
On 11/08/2026 14:55, Bonita Montero wrote:
I did run the numbers. I wasn't wrong but also not totally right.
The result of the difference between integer and fp-multiplies
is nearly zero:
Even if that were true (and it is processor-dependent, so only true on
some devices), it would be irrelevant to the OP's question.-a Floating
point "pow" does not work by repeated multiplication - both operands
are floating point.
For small values of b, an inlined integer ipow() function (or built-in feature of a language or compiler extension) will be a lot faster than
an external floating point function.-a...
For b = 3, you are just doing "a * a * a" - generated inline, ...
Am 11.08.2026 um 10:01 schrieb Lynn McGuire:
Why is there not a ipow version of pow?
ipow would return an int instead of a double.-a Or a long long int.
Integer multiplies have nearly the same cost as floating point multi-
plies. pow() is done with binary exponentation. This means that you
need a lot of bit-checks an multiplies. This is nearly the same as
with floating point numbers which don't have fractions. So you can
stick with fp-values. The only difference is the reduced amount of
bits (24 vs. 32 or 53 vs. 64).
But I don't think that's there much usage for such a function.
Am 11.08.2026 um 15:19 schrieb David Brown:
On 11/08/2026 14:55, Bonita Montero wrote:
I did run the numbers. I wasn't wrong but also not totally right.
The result of the difference between integer and fp-multiplies
is nearly zero:
Even if that were true (and it is processor-dependent, so only true on
some devices), it would be irrelevant to the OP's question.-a Floating
point "pow" does not work by repeated multiplication - both operands
are floating point.
The OP asked why there's no pow() with integers.
I said the performance
must be almost the same as the overhead of a fp-multiplication is "near-
ly the same" as with integers.
Bart said that integer multiplies are
five times faster than fp-multiplies.
I did run the numbers for a modern
machine and proved him wrong.
You did.-a You failed to mention the vital fact that this applies to some processors and not others, but it is apparently correct for Zen 4
processors at least.
It is, however, almost entirely irrelevant to the OP or to calculating
"pow" in floating point or integer arithmetic.-a Floating point "pow"
does not use multiplication (assuming the target processor has dedicated instructions for logs and anti-logs).
Am 11.08.2026 um 15:17 schrieb David Brown:
For small values of b, an inlined integer ipow() function (or built-in
feature of a language or compiler extension) will be a lot faster than
an external floating point function.-a...
Prove that.
For b = 3, you are just doing "a * a * a" - generated inline, ...
I guess Lynn didn't ask for a solution optimized for constants.
On 11/08/2026 15:27, Bonita Montero wrote:
He said that in his language (we don't know what overheads that has, or
what other instructions are used) doing "a ** b" in integers, with the example values of "a = 4" and "b = 3", was five times as fast as calling
the external MSVCRT floating point "pow" function.-a That is a completely different thing, and the only thing surprising (to me) about what he
wrote is that the difference is so small.
I did run the numbers for a modern
machine and proved him wrong.
No, you did not - you merely demonstrated that you did not understand
the OP's question and Bart's reply, or that for some reason you want to
talk about something completely different and pretend that it is
relevant.-a No one has said you were wrong about the speed of multiplications on Zen 4, because it does not matter.
The fact that floating point multiply can, in some cases, be nearly as
fast as integer multiply can be relevant to some code, and can come as a surprise to some people.-a But it has no bearing to the OP and an integer power function.
Am 11.08.2026 um 16:08 schrieb David Brown:
You did.-a You failed to mention the vital fact that this applies to
some processors and not others, but it is apparently correct for Zen 4
processors at least.
Agner has taken this numbers on dozens of CPUs, and if you compare
fp- and integer-times you've mostly the same relationship.
It is, however, almost entirely irrelevant to the OP or to calculating
"pow" in floating point or integer arithmetic.-a Floating point "pow"
does not use multiplication (assuming the target processor has
dedicated instructions for logs and anti-logs).
Of course it doesn multiplications. It multiplies base by itself as
long there are exponent bits and if an exponent bit is set the currently calulated value is multiplied by the base ^ (2 ^ n) value. For the frac-
tion bits the square root is inrementally done in the same way. That's
called binary exponentation.
On 11/08/2026 15:08, David Brown wrote:
On 11/08/2026 15:27, Bonita Montero wrote:
He said that in his language (we don't know what overheads that has,
or what other instructions are used) doing "a ** b" in integers, with
the example values of "a = 4" and "b = 3", was five times as fast as
calling the external MSVCRT floating point "pow" function.-a That is a
completely different thing, and the only thing surprising (to me)
about what he wrote is that the difference is so small.
The integer routine was equivalent to this C version:
-along long int ipow(long long a, int n) {
-a-a-a long long int res;
-a-a-a res = 1;
-a-a-a if (n < 0) {
-a-a-a-a-a-a-a res = 0;
-a-a-a } else if (n == 0) {
-a-a-a-a-a-a-a res = 1;
-a-a-a } else if (n == 1) {
-a-a-a-a-a-a-a res = a;
-a-a-a } else if ((n & 1) == 0) {-a-a-a-a-a-a-a // n is even
-a-a-a-a-a-a-a res = ipow(a*a, n/2);
-a-a-a } else {-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a // n is odd
-a-a-a-a-a-a-a res = ipow(a*a, (n-1)/2)*a;
-a-a-a }
-a-a-a return res;
-a}
If I try this instead then I get the same results (which was more like 6 times as fast as a version applying pow() to floats).
I can't run an optimised version as the loop I used will just get
optimised out.
He has numbers for dozens of x86 processors.-a There are many others that
he has not covered.-a (But he has done a truly amazing job with the x86 world.)
"pow(a, b)" is implemented approximately as "exp(b * log(a))".
This is the integer pow() code so far I wrote in C++:
I didn't test all corner cases, but for values which don't overflow the
code should be corrent. The crucial case about the performance here is
that I need a division to check for overflows; in these cases you get
a nullopt. With fp-values you get inf and that's less expensive.
This is the integer pow() code so far I wrote in C++:
template<typename Int>
constexpr optional<Int> ipow( Int b, Int e )
{
-a-a-a-aconstexpr bool Sgn = is_signed_v<Int>;
-a-a-a-ausing uint = make_unsigned_t<Int>;
-a-a-a-aif( !b )
-a-a-a-a-a-a-a return !e;
-a-a-a-auint ub, ue;
-a-a-a-aif constexpr( Sgn )
-a-a-a-a-a-a-a if( e >= 0 )
-a-a-a-a-a-a-a {
-a-a-a-a-a-a-a-a-a-a-a ub = abs( b );
-a-a-a-a-a-a-a-a-a-a-a ue = abs( e );
-a-a-a-a-a-a-a }
-a-a-a-a-a-a-a else
-a-a-a-a-a-a-a-a-a-a-a return abs( b ) == 1;
-a-a-a-aelse
-a-a-a-a-a-a-a ub = b, ue = e;
-a-a-a-auint result = 1, msk = 1, sq = ub;
-a-a-a-awhile( ue )
-a-a-a-a{
-a-a-a-a-a-a-a if( (ue & msk) )
-a-a-a-a-a-a-a {
-a-a-a-a-a-a-a-a-a-a-a uint next = result * sq;
-a-a-a-a-a-a-a-a-a-a-a if( next / sq != result )
-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a return nullopt;
-a-a-a-a-a-a-a-a-a-a-a result = next;
-a-a-a-a-a-a-a-a-a-a-a ue &= ~msk;
-a-a-a-a-a-a-a }
-a-a-a-a-a-a-a msk <<= 1;
-a-a-a-a-a-a-a if( sq * sq / sq != sq )
-a-a-a-a-a-a-a-a-a-a-a return nullopt;
-a-a-a-a-a-a-a sq *= sq;
-a-a-a-a}
-a-a-a-aif constexpr( Sgn )
-a-a-a-a-a-a-a if( bool neg = b < 0; neg && (e & 1) )
-a-a-a-a-a-a-a-a-a-a-a if( result <= (uint)numeric_limits<Int>::min() )
-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a result = -(Int)result;
-a-a-a-a-a-a-a-a-a-a-a else
-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a return nullopt;
-a-a-a-areturn result;
}
Try my benchmark. The code is much more professional and in C++.
If you are writing a real integer power function with speed in mind,If I want to compare the speed against a fp-pow() that's the right way.
don't do that.-a...
On 11/08/2026 15:56, Bonita Montero wrote:
This is the integer pow() code so far I wrote in C++:
template<typename Int>
constexpr optional<Int> ipow( Int b, Int e )
{
-a-a-a-a-aconstexpr bool Sgn = is_signed_v<Int>;
-a-a-a-a-ausing uint = make_unsigned_t<Int>;
-a-a-a-a-aif( !b )
-a-a-a-a-a-a-a-a return !e;
-a-a-a-a-auint ub, ue;
-a-a-a-a-aif constexpr( Sgn )
-a-a-a-a-a-a-a-a if( e >= 0 )
-a-a-a-a-a-a-a-a {
-a-a-a-a-a-a-a-a-a-a-a-a ub = abs( b );
-a-a-a-a-a-a-a-a-a-a-a-a ue = abs( e );
-a-a-a-a-a-a-a-a }
-a-a-a-a-a-a-a-a else
-a-a-a-a-a-a-a-a-a-a-a-a return abs( b ) == 1;
-a-a-a-a-aelse
-a-a-a-a-a-a-a-a ub = b, ue = e;
-a-a-a-a-auint result = 1, msk = 1, sq = ub;
-a-a-a-a-awhile( ue )
-a-a-a-a-a{
-a-a-a-a-a-a-a-a if( (ue & msk) )
-a-a-a-a-a-a-a-a {
-a-a-a-a-a-a-a-a-a-a-a-a uint next = result * sq;
-a-a-a-a-a-a-a-a-a-a-a-a if( next / sq != result )
-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a return nullopt;
-a-a-a-a-a-a-a-a-a-a-a-a result = next;
-a-a-a-a-a-a-a-a-a-a-a-a ue &= ~msk;
-a-a-a-a-a-a-a-a }
-a-a-a-a-a-a-a-a msk <<= 1;
-a-a-a-a-a-a-a-a if( sq * sq / sq != sq )
-a-a-a-a-a-a-a-a-a-a-a-a return nullopt;
-a-a-a-a-a-a-a-a sq *= sq;
-a-a-a-a-a}
-a-a-a-a-aif constexpr( Sgn )
-a-a-a-a-a-a-a-a if( bool neg = b < 0; neg && (e & 1) )
-a-a-a-a-a-a-a-a-a-a-a-a if( result <= (uint)numeric_limits<Int>::min() )
-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a result = -(Int)result;
-a-a-a-a-a-a-a-a-a-a-a-a else
-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a return nullopt;
-a-a-a-a-areturn result;
}
Can you package this into something I can all as ipow(a, b)?
As it is this doesn't compile by itself.
Am 11.08.2026 um 17:11 schrieb David Brown:
He has numbers for dozens of x86 processors.-a There are many others
that he has not covered.-a (But he has done a truly amazing job with
the x86 world.)
Agner covers almost all x86-microarcitecures that have been seen so far.
"pow(a, b)" is implemented approximately as "exp(b * log(a))".
Check the glibc sourcecode. Binary exponentation is the fastest way
to to that and the way with the least precision loss.
Most processors in the world are /not/ x86.
On 11/08/2026 17:20, Bonita Montero wrote:I hope that exp() and log() use base e! The exp2() and log2() functions
Am 11.08.2026 um 17:11 schrieb David Brown:
"pow(a, b)" is implemented approximately as "exp(b * log(a))".
Check the glibc sourcecode. Binary exponentation is the fastest way
to to that and the way with the least precision loss.
Let me try again.
"pow(a, b)" is implemented approximately as "exp(b * log(a))".
/Obviously/ the base used for the "exp" and "log" is base 2, since that
is the most efficient base for calculating "exp" and "log" on a binary computer, especially with standard floating point formats.
Am 11.08.2026 um 17:32 schrieb David Brown:
Most processors in the world are /not/ x86.
And do you think they've better multipliers because they've a
different architecture ? I don't.
On 2026-08-11 11:32, David Brown wrote:
On 11/08/2026 17:20, Bonita Montero wrote:I hope that exp() and log() use base e! The exp2() and log2() functions
Am 11.08.2026 um 17:11 schrieb David Brown:
"pow(a, b)" is implemented approximately as "exp(b * log(a))".
Check the glibc sourcecode. Binary exponentation is the fastest way
to to that and the way with the least precision loss.
Let me try again.
"pow(a, b)" is implemented approximately as "exp(b * log(a))".
/Obviously/ the base used for the "exp" and "log" is base 2, since that
is the most efficient base for calculating "exp" and "log" on a binary
computer, especially with standard floating point formats.
are the ones that are supposed to use base 2.
I know that on many devices, integer multipliers are faster than
floating point multipliers.-a Most processors do not have any kind
of hardware floating point - all floating point is done in software.
Once you have a die as large as for x86 processors, the cost of single- cycle floating point multipliers is not nearly as high.
But even then, many x86 processors have been designed where there are significantly more integer multiply units than floating point multiply
units - giving significantly greater integer multiply throughput.
This is not difficult to understand.-a Integer multiplications are needed more than floating point multiplications, and they are simpler and
smaller to implement.
Why is there not a ipow version of pow?
ipow would return an int instead of a double.-a Or a long long int.
real and real x int -> real might be two other implementations.All three distinct.
I didn't test all corner cases, but for values which don't overflow the
code should be corrent. The crucial case about the performance here is
that I need a division to check for overflows; in these cases you get
a nullopt. With fp-values you get inf and that's less expensive.
Why do you need all that? You basically just want ipow(a, 4) to return a*a*a*a.
If worried about overflow, then use floating point pow().
Am 11.08.2026 um 17:11 schrieb David Brown:
He has numbers for dozens of x86 processors.-a There are many others that >> he has not covered.-a (But he has done a truly amazing job with the x86
world.)
Agner covers almost all x86-microarcitecures that have been seen so far.
That doesn't include PowerPC, uMIPS, ARMv7/8/9, S390, or the myriad
of small microcontrollers and utility processors still in common use.
Am 11.08.2026 um 17:11 schrieb David Brown:
He has numbers for dozens of x86 processors.a There are many others
that he has not covered.a (But he has done a truly amazing job with
the x86 world.)
Agner covers almost all x86-microarcitecures that have been seen so
far.
"pow(a, b)" is implemented approximately as "exp(b * log(a))".
Check the glibc sourcecode. Binary exponentation is the fastest way
to to that and the way with the least precision loss.
Now I did run the numbers on that. My integer code is about four
times faster with g++ and clang++/clang-cl for all cases where
there's no overflow on ipow() *and* pow(). I didn't expect that.
Am 11.08.2026 um 19:43 schrieb bart:
Why do you need all that? You basically just want ipow(a, 4) to return
a*a*a*a.
To have variable exponents.
If worried about overflow, then use floating point pow().
I did this to compare the performance, but I didn't run the numbers on
that. I mentioned that the overflow detection needs a division, thereby making the code not competitive to a fp-version.
On 11/08/2026 17:39, Bonita Montero wrote:
Am 11.08.2026 um 17:32 schrieb David Brown:
Most processors in the world are /not/ x86.
And do you think they've better multipliers because they've a
different architecture ? I don't.
I know that on many devices, integer multipliers are faster than
floating point multipliers. Most processors do not have any kind of hardware floating point - all floating point is done in software.
For those that have hardware floating point, a many take a few cycles
to do the multiplication in hardware, because single-cycle floating
point hardware takes a lot of die space and is far less useful than single-cycle integer multiply.
Once you have a die as large as for x86 processors, the cost of
single-cycle floating point multipliers is not nearly as high.
But
even then, many x86 processors have been designed where there are significantly more integer multiply units than floating point
multiply units - giving significantly greater integer multiply
throughput.
This is not difficult to understand. Integer multiplications are
needed more than floating point multiplications, and they are simpler
and smaller to implement.
Am 11.08.2026 um 20:19 schrieb Scott Lurndal:
That doesn't include PowerPC, uMIPS, ARMv7/8/9, S390, or the myriad
of small microcontrollers and utility processors still in common use.
Do you think these architectures have faster integer-multipliers ?
On 2026-08-11 10:01, Lynn McGuire wrote:
Why is there not a ipow version of pow?
It may sound strange (at first glance), but the negated answer would
probably be easier to answer.
If there were one one could easily formulate some advantages compared
to the floating point versions.
But since there isn't one we can only speculate and say that possible advantages were probably not considered worthwhile an addition.
Other languages support it, probably with overloaded operators for a
unified looking expressions experience, but underlying functions may nonetheless differ (depending on the involved types and signatures).
ipow would return an int instead of a double.-a Or a long long int.
Yes. Even the semantics may vary (compared to a float version); e.g.
while a (primitive) float version might be formulated using exp/ln
for the whole range of numbers an-a int x int -> int-a version might
not be defined for exponents less than zero. (Or, as I've noticed in
one of the posted algorithms, might just return 0.) And-a real x real
real-a and-a real x int -> real-a might be two other implementations.All three distinct.
Curious; is your question just an academical one (out of interest) or
do you have a specific demand for it?
When I started programming decades ago accuracy was an issue, so the
exp/ln approach was not always appropriate. Also speed of computation.
But things have changed since then, concerning accuracy of floats and
the speed of math operations. So check your requirements and make sure whether the supported "pow" functions do what you need, else implement
one or find a good one on the Internet. (I've seen a sensible looking
version posted here in this thread.)
Janis
Bonita Montero <Bonita.Montero@gmail.com> writes:
Am 11.08.2026 um 20:19 schrieb Scott Lurndal:
That doesn't include PowerPC, uMIPS, ARMv7/8/9, S390, or the myriad
of small microcontrollers and utility processors still in common
use.
Do you think these architectures have faster integer-multipliers ?
Depends on clock speed. The Neoverse-N2 integer multiply instruction
has a latency of 2 cycles and throughput of one per cycle. Seems
fast enough.
Those same latency and throughput numbers apply to the multiply-add
and multiply-subtract instructions as well.
On Tue, 8/11/2026 7:11 AM, Bonita Montero wrote:
Am 11.08.2026 um 10:01 schrieb Lynn McGuire:
Why is there not a ipow version of pow?
ipow would return an int instead of a double.-a Or a long long int.
Integer multiplies have nearly the same cost as floating point multi-
plies. pow() is done with binary exponentation. This means that you
need a lot of bit-checks an multiplies. This is nearly the same as
with floating point numbers which don't have fractions. So you can
stick with fp-values. The only difference is the reduced amount of
bits (24 vs. 32 or 53 vs. 64).
But I don't think that's there much usage for such a function.
With pow(), you can do pow(2.2,3.3) ==> 13.49
https://github.com/lattera/glibc/blob/master/sysdeps/ieee754/dbl-64/e_pow.c
/* x^y =e^(y log (X)) */
( https://stackoverflow.com/questions/40824677/how-is-pow-calculated-in-c )
There is also a .tbl file in that source.
Apparently the processor has a mixed method for doing log(),
using a Taylor series and a lookup table of some sort. That suggests, approximately, that using log() of something isn't going to be
blindingly fast. But that also does not mean anyone has to like the
valid range or how many digits it puts out. A person could craft
their own log().
There are some conditional checks for pow(). Maybe ipow()
has some things to check too.
And you can go on a shopping spree. There is more than one of
these out there, but they are cut for speed, not necessarily
for considering absolutely every condition. The domain and range
could differ, compared to a library quality implementation.
# ipow()
https://gist.github.com/orlp/3551590
Paul
On 8/11/2026 12:15 PM, Janis Papanagnou wrote:
On 2026-08-11 10:01, Lynn McGuire wrote:
Why is there not a ipow version of pow?
It may sound strange (at first glance), but the negated answer would
probably be easier to answer.
If there were one one could easily formulate some advantages compared
to the floating point versions.
But since there isn't one we can only speculate and say that possible
advantages were probably not considered worthwhile an addition.
Other languages support it, probably with overloaded operators for a
unified looking expressions experience, but underlying functions may
nonetheless differ (depending on the involved types and signatures).
ipow would return an int instead of a double.-a Or a long long int.
Yes. Even the semantics may vary (compared to a float version); e.g.
while a (primitive) float version might be formulated using exp/ln
for the whole range of numbers an-a int x int -> int-a version might
not be defined for exponents less than zero. (Or, as I've noticed in
one of the posted algorithms, might just return 0.) And-a real x real
real-a and-a real x int -> real-a might be two other implementations.All three distinct.
Curious; is your question just an academical one (out of interest) or
do you have a specific demand for it?
When I started programming decades ago accuracy was an issue, so the
exp/ln approach was not always appropriate. Also speed of computation.
But things have changed since then, concerning accuracy of floats and
the speed of math operations. So check your requirements and make sure
whether the supported "pow" functions do what you need, else implement
one or find a good one on the Internet. (I've seen a sensible looking
version posted here in this thread.)
Janis
I have pow of an integer to an integer power in my code, yes.
I am converting 800,000 lines of F77 code to C++.
Lynn
On 8/11/2026 4:41 PM, Lynn McGuire wrote:
On 8/11/2026 12:15 PM, Janis Papanagnou wrote:
On 2026-08-11 10:01, Lynn McGuire wrote:
Why is there not a ipow version of pow?
It may sound strange (at first glance), but the negated answer would
probably be easier to answer.
If there were one one could easily formulate some advantages compared
to the floating point versions.
But since there isn't one we can only speculate and say that possible
advantages were probably not considered worthwhile an addition.
Other languages support it, probably with overloaded operators for a
unified looking expressions experience, but underlying functions may
nonetheless differ (depending on the involved types and signatures).
ipow would return an int instead of a double.-a Or a long long int.
Yes. Even the semantics may vary (compared to a float version); e.g.
while a (primitive) float version might be formulated using exp/ln
for the whole range of numbers an-a int x int -> int-a version might
not be defined for exponents less than zero. (Or, as I've noticed in
one of the posted algorithms, might just return 0.) And-a real x real
real-a and-a real x int -> real-a might be two other implementations. >>> All three distinct.
Curious; is your question just an academical one (out of interest) or
do you have a specific demand for it?
When I started programming decades ago accuracy was an issue, so the
exp/ln approach was not always appropriate. Also speed of computation.
But things have changed since then, concerning accuracy of floats and
the speed of math operations. So check your requirements and make sure
whether the supported "pow" functions do what you need, else implement
one or find a good one on the Internet. (I've seen a sensible looking
version posted here in this thread.)
Janis
I have pow of an integer to an integer power in my code, yes.
I am converting 800,000 lines of F77 code to C++.
Lynn
Here is some of the code:
-a-a-a longint i__1 = *ng;
-a-a-a for (ig = 1; ig <= i__1; ++ig) {
-a-a-a-a-a-a-a ihold = 0;
-a-a-a-a-a-a-a ntype = ntpg[ig - 1];
-a-a-a-a-a-a-a longint i__2 = ntype;
-a-a-a-a-a-a-a for (it = 1; it <= i__2; ++it) {
-a-a-a-a-a-a-a-a-a-a-a ++itup;
-a-a-a-a-a-a-a-a-a-a-a igo = grou[itup - 1];
-a-a-a-a-a-a-a-a-a-a-a if (it == 1) {
-a-a-a-a-a-a-a-a-a-a-a ihldty = igo;
-a-a-a-a-a-a-a-a-a-a-a }
-a-a-a-a-a-a-a-a-a-a-a iun = defaul[igo - 1];
-a-a-a-a-a-a-a-a-a-a-a if (igo == 2 && it > 1) {
-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a iun = 2;
-a-a-a-a-a-a-a-a-a-a-a }
-a-a-a-a-a-a-a-a-a-a-a if (*iflag == 2 && igo == 8) {
-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a iun = 2;
-a-a-a-a-a-a-a-a-a-a-a }
-a-a-a-a-a-a-a-a-a-a-a if (*iflag == 2 && igo == 7) {
-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a iun = 1;
-a-a-a-a-a-a-a-a-a-a-a }
-a-a-a-a-a-a-a-a-a-a-a longint i__3 = it - 1;
-a-a-a-a-a-a-a-a-a-a-a ihold += iun * pow (mul, i__3);
-a-a-a-a-a-a-a }
[...]On 2026-08-11 10:01, Lynn McGuire wrote:
Why is there not a ipow version of pow?
I have pow of an integer to an integer power in my code, yes.
I am converting 800,000 lines of F77 code to C++.
Lynn McGuire <lynnmcguire5@gmail.com> writes:
[...]
[...]On 2026-08-11 10:01, Lynn McGuire wrote:
Why is there not a ipow version of pow?
I have pow of an integer to an integer power in my code, yes.
I am converting 800,000 lines of F77 code to C++.
It's a perfectly valid question, but I don't think any answer is
going to help you with your immediate problem.
I think the best solution to your immediate problem would be to write
your own ipow() function(s). Depending on the actual exponents,
it might be worth optimizing it by using squaring, so for example
ipow(n, 4) performs 2 multiplications rather than 3. As I recall,
you're already modifying the C code produced by f2c.
I have pow of an integer to an integer power in my code, yes.
I am converting 800,000 lines of F77 code to C++.
Lynn
Here is some of the code:
-a-a-a-a longint i__1 = *ng;
-a-a-a-a for (ig = 1; ig <= i__1; ++ig) {
-a-a-a-a-a-a-a-a ihold = 0;
-a-a-a-a-a-a-a-a ntype = ntpg[ig - 1];
-a-a-a-a-a-a-a-a longint i__2 = ntype;
-a-a-a-a-a-a-a-a for (it = 1; it <= i__2; ++it) {
-a-a-a-a-a-a-a-a-a-a-a-a ++itup;
-a-a-a-a-a-a-a-a-a-a-a-a igo = grou[itup - 1];
-a-a-a-a-a-a-a-a-a-a-a-a if (it == 1) {
-a-a-a-a-a-a-a-a-a-a-a-a ihldty = igo;
-a-a-a-a-a-a-a-a-a-a-a-a }
-a-a-a-a-a-a-a-a-a-a-a-a iun = defaul[igo - 1];
-a-a-a-a-a-a-a-a-a-a-a-a if (igo == 2 && it > 1) {
-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a iun = 2;
-a-a-a-a-a-a-a-a-a-a-a-a }
-a-a-a-a-a-a-a-a-a-a-a-a if (*iflag == 2 && igo == 8) {
-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a iun = 2;
-a-a-a-a-a-a-a-a-a-a-a-a }
-a-a-a-a-a-a-a-a-a-a-a-a if (*iflag == 2 && igo == 7) {
-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a iun = 1;
-a-a-a-a-a-a-a-a-a-a-a-a }
-a-a-a-a-a-a-a-a-a-a-a-a longint i__3 = it - 1;
-a-a-a-a-a-a-a-a-a-a-a-a ihold += iun * pow (mul, i__3);
-a-a-a-a-a-a-a-a }
That doesn't look like Fortran! So it's already been converted, and it
was decided to turn A**B (or whatever Fortran used) into pow(A, B)?
However I don't really see the problem. Just write some function 'ipow'
for example (you already have a link to one), and use it in place of 'pow'.
On 11/08/2026 17:20, Bonita Montero wrote:
Am 11.08.2026 um 17:11 schrieb David Brown:
He has numbers for dozens of x86 processors.-a There are many others
that he has not covered.-a (But he has done a truly amazing job with
the x86 world.)
Agner covers almost all x86-microarcitecures that have been seen so far.
Most processors in the world are /not/ x86. On some devices, a floating point multiply will be perhaps 200 times slower than an integer
multiply. You may also find that on some devices with 32-bit GPRs and 64-bit hardware floating point, floating point multiplication could be faster than 64-bit integer multiplication. Anger covers the x86 world,
not the entire processor world.
"pow(a, b)" is implemented approximately as "exp(b * log(a))".
Check the glibc sourcecode. Binary exponentation is the fastest way
to to that and the way with the least precision loss.
Let me try again.
"pow(a, b)" is implemented approximately as "exp(b * log(a))".
/Obviously/ the base used for the "exp" and "log" is base 2, since that
is the most efficient base for calculating "exp" and "log" on a binary computer, especially with standard floating point formats.
On 8/11/2026 5:33 PM, Keith Thompson wrote:
Lynn McGuire <lynnmcguire5@gmail.com> writes:
[...]
[...]On 2026-08-11 10:01, Lynn McGuire wrote:
Why is there not a ipow version of pow?
I have pow of an integer to an integer power in my code, yes.It's a perfectly valid question, but I don't think any answer is
I am converting 800,000 lines of F77 code to C++.
going to help you with your immediate problem.
I think the best solution to your immediate problem would be to
write
your own ipow() function(s). Depending on the actual exponents,
it might be worth optimizing it by using squaring, so for example
ipow(n, 4) performs 2 multiplications rather than 3. As I recall,
you're already modifying the C code produced by f2c.
I agree with writing my own "long long int ipow (long long int, long
long int)" code. Both situations that I have found are in my input
file parser code dealing with dimensional unit conversions. So
efficiency is not a big deal, but rigorousness and correctness is very important to me.
On 11/08/2026 15:56, Bonita Montero wrote:[snip]
This is the integer pow() code so far I wrote in C++:
Can you package this into something I can all as ipow(a, b)?
As it is this doesn't compile by itself.
Why is there not a ipow version of pow?
Depends on clock speed. The Neoverse-N2 integer multiply instruction
has a latency of 2 cycles and throughput of one per cycle. Seems
fast enough.
People don't care about integer overflow in general, why should they here?
Am 11.08.2026 um 16:08 schrieb David Brown:
You did. You failed to mention the vital fact that this applies to
some processors and not others, but it is apparently correct for Zen 4
processors at least.
Agner has taken this numbers on dozens of CPUs, and if you compare
fp- and integer-times you've mostly the same relationship.
It is, however, almost entirely irrelevant to the OP or to calculating
"pow" in floating point or integer arithmetic. Floating point "pow"
does not use multiplication (assuming the target processor has
dedicated instructions for logs and anti-logs).
Of course it doesn multiplications. It multiplies base by itself as
long there are exponent bits and if an exponent bit is set the currently calulated value is multiplied by the base ^ (2 ^ n) value. For the frac-
tion bits the square root is inrementally done in the same way. That's
called binary exponentation.
When I tried to compile this, it said: C:/tdm/include/c++/16.1.0/optional:1256: constexpr _Tp&& std::optional<_Tp>::operator*() && [with _T
p = long long int]: Assertion 'this->_M_is_engaged()' failed.
Lynn McGuire <lynnmcguire5@gmail.com> writes:
On 8/11/2026 5:33 PM, Keith Thompson wrote:
Lynn McGuire <lynnmcguire5@gmail.com> writes:
[...]
[...]On 2026-08-11 10:01, Lynn McGuire wrote:
Why is there not a ipow version of pow?
I have pow of an integer to an integer power in my code, yes.It's a perfectly valid question, but I don't think any answer is
I am converting 800,000 lines of F77 code to C++.
going to help you with your immediate problem.
I think the best solution to your immediate problem would be to
write
your own ipow() function(s). Depending on the actual exponents,
it might be worth optimizing it by using squaring, so for example
ipow(n, 4) performs 2 multiplications rather than 3. As I recall,
you're already modifying the C code produced by f2c.
I agree with writing my own "long long int ipow (long long int, long
long int)" code. Both situations that I have found are in my input
file parser code dealing with dimensional unit conversions. So
efficiency is not a big deal, but rigorousness and correctness is very
important to me.
The name "ipow" doesn't suggest an operation on long long.
If you want generality, you might want something like:
int ipow(int, int);
long ipowl(long, int);
long long ipowll(long long, int);
(Or you can overload ipow() if you're using C++, but I thought
you were just converting Fortran to C, which makes me wonder why
you cross-posted.)
Note that I'm assuming the exponent is an int in all cases.
On Tue, 11 Aug 2026 03:01:07 -0500, Lynn McGuire wrote:
Why is there not a ipow version of pow?
Perhaps for the same reason there arenrCOt integer log functions: itrCOs
all down to dynamic range. Logs and exponentials by their nature are
liable to cover a huge range of magnitudes in either the argument
(logarithm) or result (exponential). Integer formats in common use do
not cater for this. Whereas with floating-point -- well, itrCOs there in
the name, isnrCOt it?
On 11/08/2026 18:56, Bonita Montero wrote:
Am 11.08.2026 um 19:43 schrieb bart:
Why do you need all that? You basically just want ipow(a, 4) to
return a*a*a*a.
To have variable exponents.
You mean ipow(a, b) where b is known at runtime?
Then that's exactly what I mean. This should be the equivalant of
a*a*a...*a with b-1 multiplications, but done more efficiently.
For example my function can calculate ipow(1, 1000000) 10,000 times
faster than a version that simply does 1000000 or so multiplications.
If worried about overflow, then use floating point pow().
I did this to compare the performance, but I didn't run the numbers on
that. I mentioned that the overflow detection needs a division, thereby
making the code not competitive to a fp-version.
People don't care about integer overflow in general, why should they here?
However if large-magnitude results (greater than 2**63) are likely, then they should go with floats and use pow, at a loss of some precision.
Or use the same algorithm with a bigint library as I also do.
On Tue, 11 Aug 2026 03:01:07 -0500, Lynn McGuire wrote:
Why is there not a ipow version of pow?
Perhaps for the same reason there arenrCOt integer log functions: itrCOs
all down to dynamic range. Logs and exponentials by their nature are
liable to cover a huge range of magnitudes in either the argument
(logarithm) or result (exponential). Integer formats in common use do
not cater for this. Whereas with floating-point -- well, itrCOs there in
the name, isnrCOt it?
And I thought it is entirely obvious that when you are actually
implementing a floating point power function on a binary computer
using floating point formats specified in binary, it is most efficient
to use base 2 for the log and anti-log. If you had a floating point
format that used base 10, you'd probably want to use base 10 for the
log and anti-log.
David Brown <david.brown@hesbynett.no> writes:
[...]
And I thought it is entirely obvious that when you are actually
implementing a floating point power function on a binary computer
using floating point formats specified in binary, it is most efficient
to use base 2 for the log and anti-log. If you had a floating point
format that used base 10, you'd probably want to use base 10 for the
log and anti-log.
Is it obvious? It had never occurred to me.
log and exp are certainly more mathematically straightforward in
base e than in other bases. Of course floating-point is typically
binary, but I didn't know that would imply that log(x) base 2 is
easier to compute that log(x) base e. I've always assumed that
base e is more efficient than other bases.
Also, I vaguely recall that though x**y is mathematically equivalent
to exp(y * log(x)), that's not the most efficient and/or accurate
way to compute it.
There was a very little mistake with my last code: If the exponent is negative (immediate return), abs( base ) == 1 and the exponent is odd,
the return is not 1 vs. 0 but -1 vs 0.
And there are two *theoretical* UBs I cover. If either base or exponent
have the maximum negative values negating them is UB. So now I do a
0u - (uint)value. But that's rather aesthetics on today's platforms.
Claude and GPT don't complain about my code now.
Didn't think that this code would be so tricky at last. And the major
issue with my code is: no one needs a pow for integers, even my pow()
is faster for valid values than a fp-pow().
I would not trust an LLM-AI to do an off-the-cuff analysis
of the code for this one. Claude may have a slight edge over
the competition, but LLM-AI really do make mistakes, and it
isn't pretty when they do.
Am 11.08.2026 um 23:10 schrieb Scott Lurndal:
Depends on clock speed. The Neoverse-N2 integer multiply instruction
has a latency of 2 cycles and throughput of one per cycle. Seems
fast enough.
According to the AI it's three cycles.
Bonita Montero <Bonita.Montero@gmail.com> writes:
According to the AI it's three cycles.
Yet another case where the AI is wrong.
Am 12.08.2026 um 16:19 schrieb Scott Lurndal:
Bonita Montero <Bonita.Montero@gmail.com> writes:
According to the AI it's three cycles.
Yet another case where the AI is wrong.
Show me the documentation.
Am 11.08.2026 um 23:10 schrieb Scott Lurndal:
Depends on clock speed. The Neoverse-N2 integer multiply
instruction has a latency of 2 cycles and throughput of one per
cycle. Seems fast enough.
According to the AI it's three cycles.
Am 12.08.2026 um 15:11 schrieb Paul:
I would not trust an LLM-AI to do an off-the-cuff analysis
of the code for this one. Claude may have a slight edge over
the competition, but LLM-AI really do make mistakes, and it
isn't pretty when they do.
If Claude sees 95% of all issues that's useful.
David Brown <david.brown@hesbynett.no> writes:
[...]
And I thought it is entirely obvious that when you are actually implementing a floating point power function on a binary computer
using floating point formats specified in binary, it is most
efficient to use base 2 for the log and anti-log. If you had a
floating point format that used base 10, you'd probably want to use
base 10 for the log and anti-log.
Is it obvious? It had never occurred to me.
log and exp are certainly more mathematically straightforward in
base e than in other bases.
Of course floating-point is typically
binary, but I didn't know that would imply that log(x) base 2 is
easier to compute that log(x) base e. I've always assumed that
base e is more efficient than other bases.
Also, I vaguely recall that though x**y is mathematically equivalent
to exp(y * log(x)), that's not the most efficient and/or accurate
way to compute it.
On 12/08/2026 00:53, Waldek Hebisch wrote:
In comp.lang.c David Brown <david.brown@hesbynett.no> wrote:
On 11/08/2026 17:20, Bonita Montero wrote:
Am 11.08.2026 um 17:11 schrieb David Brown:Most processors in the world are /not/ x86. On some devices, a floating >>> point multiply will be perhaps 200 times slower than an integer
He has numbers for dozens of x86 processors.-a There are many others >>>>> that he has not covered.-a (But he has done a truly amazing job with >>>>> the x86 world.)
Agner covers almost all x86-microarcitecures that have been seen so far. >>>
multiply. You may also find that on some devices with 32-bit GPRs and
64-bit hardware floating point, floating point multiplication could be
faster than 64-bit integer multiplication. Anger covers the x86 world,
not the entire processor world.
"pow(a, b)" is implemented approximately as "exp(b * log(a))".
Check the glibc sourcecode. Binary exponentation is the fastest way
to to that and the way with the least precision loss.
Let me try again.
"pow(a, b)" is implemented approximately as "exp(b * log(a))".
In floating point this formula is loosing accuracy for very large
'a'. The is pressure on library authors to deliver high accuracy,
so there is nontrivial chance that library is using much more
complicated (and expensive) method to compute the resut.
That's why I wrote "approximately". I realise there are a lot of
details involved to make the calculation of "pow" work accurately over a wide range of values. My point was merely that calculation of powers
with floating point is done with that mathematical formula at heart,
which is entirely different from how an integer power function is
usually calculated (by repeated multiplication).
No, "log" and "exp" as words alone do /not/ imply base "e" - or any
/Obviously/ the base used for the "exp" and "log" is base 2, since that
is the most efficient base for calculating "exp" and "log" on a binary
computer, especially with standard floating point formats.
This is rather unfortunate statement. Logaritms are defined for
any base and "pow(a, b)" has alternative name as "exponential function
with base a". Of course log above is natural log, that is base 'e'
and 'exp(x)' means "e to power a", so normaly wordy version would be
"exponential with base e".
other specific base. Within some contexts, there may be an implication
from common usage - and "context" may include "that's what we wrote at school or university in my country", "that's the name used in the
standard library", "that's the buttons on my calculator", etc. To be
fair, these are the names for the functions in base "e" in the C
standard library, and that is a reasonable context to use in these
Usenet groups. I should therefore have been a bit clearer that that was
not what I meant.
I thought it was quite clear that I was referring to a general log and anti-log function pair, writing as mathematics and not as a C
expression. From the maths viewpoint, the base does not matter (at
least for a sane base - a real number greater than 1), as long as it is consistent.
And I thought it is entirely obvious that when you are actually
implementing a floating point power function on a binary computer using floating point formats specified in binary, it is most efficient to use
base 2 for the log and anti-log. If you had a floating point format
that used base 10, you'd probably want to use base 10 for the log and anti-log.
This is all implementation detail, and not the focus of my post.
But again, given that "exp" and "log" are base "e" functions in the C standard library, I should have been clearer there.
On Wed, 12 Aug 2026 03:58:16 -0700
Keith Thompson <Keith.S.Thompson+u@gmail.com> wrote:
David Brown <david.brown@hesbynett.no> writes:
[...]
And I thought it is entirely obvious that when you are actually
implementing a floating point power function on a binary computer
using floating point formats specified in binary, it is most
efficient to use base 2 for the log and anti-log. If you had a
floating point format that used base 10, you'd probably want to use
base 10 for the log and anti-log.
Is it obvious? It had never occurred to me.
log and exp are certainly more mathematically straightforward in
base e than in other bases.
Only near x=1 for log(x) and near x=0 for exp(x).
Of course floating-point is typically
binary, but I didn't know that would imply that log(x) base 2 is
easier to compute that log(x) base e. I've always assumed that
base e is more efficient than other bases.
You are mostly wrong. David is mostly correct.
Also, I vaguely recall that though x**y is mathematically equivalent
to exp(y * log(x)), that's not the most efficient and/or accurate
way to compute it.
Apart from corner cases, it is the most efficient.
And I am pretty sure that it's sufficiently accurate for most uses,
including you typical C library. I did no deep numeric analysis, but my intuition suggest that as long as underlaying primitives, i.e. log2 and
2**x, are well implemented, i.e. their maximal error is under 0.6 ULP,
then the worst case error of combined calculation should be below 2.5--
ULP and most likely even lower than that. Which is good enough.
For more than 50% of inputs you will end within 1 ULP.
Of course, you don't do it stupidly. You start by splitting a with
frexp() and splitting b to integer and fractional, probably with
fractional in range [-0.5:0.5]. Then you take away trivial parts, i.e
integer power of two. But then you come to the main part and this part
is as David suggested.
Michael S <already5chosen@yahoo.com> writes:
On Wed, 12 Aug 2026 03:58:16 -0700
Keith Thompson <Keith.S.Thompson+u@gmail.com> wrote:
David Brown <david.brown@hesbynett.no> writes:
[...]
And I thought it is entirely obvious that when you are actually
implementing a floating point power function on a binary computer
using floating point formats specified in binary, it is most
efficient to use base 2 for the log and anti-log. If you had a
floating point format that used base 10, you'd probably want to
use base 10 for the log and anti-log.
Is it obvious? It had never occurred to me.
log and exp are certainly more mathematically straightforward in
base e than in other bases.
Only near x=1 for log(x) and near x=0 for exp(x).
Can you explain what you mean by that?
Mathematically, exp(x) (base e) is described by the Taylor series.
In clumsy ASCII notation, it's:
1 + x + x**2/2! + x**3/3! + x**4/4! + ...
b**x, were b is a base other than e (often 2 or 10) is
exp(x * log(base)), where exp() and log() are base e. In other
words, exp and log for bases other than e are most straightforwardly
defined on top of exp and log for base e.
That's what I meant by "more mathematically straightforward".
If you say there are computational reasons why exp2 and log2 are
advantageous when using binary floating-point, I can believe that.
I just don't understand the reasons (and to be honest, I'm not sure
I'd understand an explanation without more effort than I'm willing
to expend, unless somebody wants to pay me to work on this stuff).
On Wed, 12 Aug 2026 13:44:50 -0700
Keith Thompson <Keith.S.Thompson+u@gmail.com> wrote:
Michael S <already5chosen@yahoo.com> writes:
On Wed, 12 Aug 2026 03:58:16 -0700
Keith Thompson <Keith.S.Thompson+u@gmail.com> wrote:
David Brown <david.brown@hesbynett.no> writes:
[...]
And I thought it is entirely obvious that when you are actually
implementing a floating point power function on a binary computer
using floating point formats specified in binary, it is most
efficient to use base 2 for the log and anti-log. If you had a
floating point format that used base 10, you'd probably want to
use base 10 for the log and anti-log.
Is it obvious? It had never occurred to me.
log and exp are certainly more mathematically straightforward in
base e than in other bases.
Only near x=1 for log(x) and near x=0 for exp(x).
Can you explain what you mean by that?
Mathematically, exp(x) (base e) is described by the Taylor series.
In clumsy ASCII notation, it's:
1 + x + x**2/2! + x**3/3! + x**4/4! + ...
b**x, were b is a base other than e (often 2 or 10) is
exp(x * log(base)), where exp() and log() are base e. In other
words, exp and log for bases other than e are most straightforwardly
defined on top of exp and log for base e.
That's what I meant by "more mathematically straightforward".
If you say there are computational reasons why exp2 and log2 are
advantageous when using binary floating-point, I can believe that.
I just don't understand the reasons (and to be honest, I'm not sure
I'd understand an explanation without more effort than I'm willing
to expend, unless somebody wants to pay me to work on this stuff).
It's late here and I want to sleep, so very briefly:
The best computational way to calculate a**x for constant a on
relatively big interval of x, like [0:1] or [-0.5:0.5] is not through evaluation of polynomial of very high degree, but by splitting
interval into sub ranges and calculating y = Yi * a**(x-Xi) where
Yi is tabulated and may be Xi tabulated too, or may be Xi just regularly spaced. For double precision and for speed/space/precision requirements
of C math library you will probably want many dozen of intervals, or
low hundreds. That allows much lower degree of poly for a**(x-Xi).
And to lower degree even further you use Chebyshev series or may be
even series derived by Remez exchange algorithm rather than Taylor
series. It means that even for a=e the second coefficient is not 1 and
likely the 1st coefficient is also not 1. So, a=e has no advantage vs
a=2. Of course, in this part of calculation a=2 also holds no
advantages vs any other base, but it has advantages in other parts of
of solution.
Different but ideologically similar reasoning applies to natural
log vs log2.
On Wed, 12 Aug 2026 06:41:08 +0200
Bonita Montero <Bonita.Montero@gmail.com> wrote:
Am 11.08.2026 um 23:10 schrieb Scott Lurndal:
Depends on clock speed. The Neoverse-N2 integer multiply
instruction has a latency of 2 cycles and throughput of one per
cycle. Seems fast enough.
According to the AI it's three cycles.
3 cycles is umulh. Normal umul/imul is 2.
You AI probably can't distinguish between Neoverse-N2 (derived from Cortex-A710, which is ARMv9 variant of A78) and Neoverse-N1 (derived
from Cortex-A76).
It is certainly convenient to be able to write 2**32 instead of
1<<32, where it is so easy to write 2<<32 by mistake.
On 8/11/2026 11:26 PM, Lawrence DrCOOliveiro wrote:
On Tue, 11 Aug 2026 03:01:07 -0500, Lynn McGuire wrote:
Why is there not a ipow version of pow?
Perhaps for the same reason there arenrCOt integer log functions: itrCOs
all down to dynamic range. Logs and exponentials by their nature are
liable to cover a huge range of magnitudes in either the argument
(logarithm) or result (exponential). Integer formats in common use do
not cater for this. Whereas with floating-point -- well, itrCOs there in
the name, isnrCOt it?
This is why you calculate and return a long long int.-a Or maybe even a 128 bit int.
Lynn
On 8/12/2026 4:24 PM, Michael S wrote:
On Wed, 12 Aug 2026 13:44:50 -0700
Keith Thompson <Keith.S.Thompson+u@gmail.com> wrote:
Michael S <already5chosen@yahoo.com> writes:
On Wed, 12 Aug 2026 03:58:16 -0700
Keith Thompson <Keith.S.Thompson+u@gmail.com> wrote:
David Brown <david.brown@hesbynett.no> writes:
[...]
And I thought it is entirely obvious that when you are actually
implementing a floating point power function on a binary computer
using floating point formats specified in binary, it is most
efficient to use base 2 for the log and anti-log.-a If you had a
floating point format that used base 10, you'd probably want to
use base 10 for the log and anti-log.
Is it obvious?-a It had never occurred to me.
log and exp are certainly more mathematically straightforward in
base e than in other bases.
Only near x=1 for log(x) and near x=0 for exp(x).
Can you explain what you mean by that?
Mathematically, exp(x) (base e) is described by the Taylor series.
In clumsy ASCII notation, it's:
-a-a-a-a 1 + x + x**2/2! + x**3/3! + x**4/4! + ...
b**x, were b is a base other than e (often 2 or 10) is
exp(x * log(base)), where exp() and log() are base e.-a In other
words, exp and log for bases other than e are most straightforwardly
defined on top of exp and log for base e.
That's what I meant by "more mathematically straightforward".
If you say there are computational reasons why exp2 and log2 are
advantageous when using binary floating-point, I can believe that.
I just don't understand the reasons (and to be honest, I'm not sure
I'd understand an explanation without more effort than I'm willing
to expend, unless somebody wants to pay me to work on this stuff).
It's late here and I want to sleep, so very briefly:
The best computational way to calculate a**x for constant a on
relatively big interval of x, like [0:1] or [-0.5:0.5] is not through
evaluation of polynomial of very high degree, but by splitting
interval into sub ranges and calculating y = Yi * a**(x-Xi) where
Yi is tabulated and may be Xi tabulated too, or may be Xi just regularly
spaced. For double precision and for speed/space/precision requirements
of C math library you will probably want many dozen of intervals, or
low hundreds. That allows much lower degree of poly for a**(x-Xi).
And to lower degree even further you use Chebyshev series or may be
even series derived by Remez exchange algorithm rather than Taylor
series. It means that even for a=e the second coefficient is not 1 and
likely the 1st coefficient is also not 1. So, a=e has no advantage vs
a=2. Of course, in this part of calculation a=2 also holds no
advantages vs any other base, but it has advantages in other parts of
of solution.
Different but ideologically similar reasoning applies to natural
log vs log2.
I have found over the years that 200 points seems to be best when
performing a numerical integration of a curve.-a For me, 200 points is
the point where diminishing returns has set in.-a Of course, YMMV.
Why is there not a ipow version of pow?
ipow would return an int instead of a double.-a Or a long long int.
Thanks,
Lynn
On 8/12/2026 7:05 AM, Bonita Montero wrote:
Am 12.08.2026 um 15:11 schrieb Paul:
I would not trust an LLM-AI to do an off-the-cuff analysis
of the code for this one. Claude may have a slight edge over
the competition, but LLM-AI really do make mistakes, and it
isn't pretty when they do.
If Claude sees 95% of all issues that's useful.
Why not use your own mind, for your own work?
Michael S <already5chosen@yahoo.com> writes:
On Wed, 12 Aug 2026 03:58:16 -0700
Keith Thompson <Keith.S.Thompson+u@gmail.com> wrote:
David Brown <david.brown@hesbynett.no> writes:
[...]
And I thought it is entirely obvious that when you are actually
implementing a floating point power function on a binary computer
using floating point formats specified in binary, it is most
efficient to use base 2 for the log and anti-log. If you had a
floating point format that used base 10, you'd probably want to use
base 10 for the log and anti-log.
Is it obvious? It had never occurred to me.
log and exp are certainly more mathematically straightforward in
base e than in other bases.
Only near x=1 for log(x) and near x=0 for exp(x).
Can you explain what you mean by that?
Mathematically, exp(x) (base e) is described by the Taylor series.
In clumsy ASCII notation, it's:
1 + x + x**2/2! + x**3/3! + x**4/4! + ...
b**x, were b is a base other than e (often 2 or 10) is
exp(x * log(base)), where exp() and log() are base e. In other
words, exp and log for bases other than e are most straightforwardly
defined on top of exp and log for base e.
That's what I meant by "more mathematically straightforward".
If you say there are computational reasons why exp2 and log2 are
advantageous when using binary floating-point, I can believe that.
I just don't understand the reasons (and to be honest, I'm not sure
I'd understand an explanation without more effort than I'm willing
to expend, unless somebody wants to pay me to work on this stuff).
Am 12.08.2026 um 21:40 schrieb Chris M. Thomasson:
On 8/12/2026 7:05 AM, Bonita Montero wrote:
Am 12.08.2026 um 15:11 schrieb Paul:
I would not trust an LLM-AI to do an off-the-cuff analysis
of the code for this one. Claude may have a slight edge over
the competition, but LLM-AI really do make mistakes, and it
isn't pretty when they do.
If Claude sees 95% of all issues that's useful.
Why not use your own mind, for your own work?
Why are a lot of developers working in teams and not only on their own ?
On 12/08/2026 23:49, Lynn McGuire wrote:
On 8/12/2026 4:24 PM, Michael S wrote:
On Wed, 12 Aug 2026 13:44:50 -0700
Keith Thompson <Keith.S.Thompson+u@gmail.com> wrote:
Michael S <already5chosen@yahoo.com> writes:
On Wed, 12 Aug 2026 03:58:16 -0700
Keith Thompson <Keith.S.Thompson+u@gmail.com> wrote:
David Brown <david.brown@hesbynett.no> writes:
[...]
And I thought it is entirely obvious that when you are actually
implementing a floating point power function on a binary computer >>>>>>> using floating point formats specified in binary, it is most
efficient to use base 2 for the log and anti-log.-a If you had a >>>>>>> floating point format that used base 10, you'd probably want to
use base 10 for the log and anti-log.
Is it obvious?-a It had never occurred to me.
log and exp are certainly more mathematically straightforward in
base e than in other bases.
Only near x=1 for log(x) and near x=0 for exp(x).
Can you explain what you mean by that?
Mathematically, exp(x) (base e) is described by the Taylor series.
In clumsy ASCII notation, it's:
-a-a-a-a 1 + x + x**2/2! + x**3/3! + x**4/4! + ...
b**x, were b is a base other than e (often 2 or 10) is
exp(x * log(base)), where exp() and log() are base e.-a In other
words, exp and log for bases other than e are most straightforwardly
defined on top of exp and log for base e.
That's what I meant by "more mathematically straightforward".
If you say there are computational reasons why exp2 and log2 are
advantageous when using binary floating-point, I can believe that.
I just don't understand the reasons (and to be honest, I'm not sure
I'd understand an explanation without more effort than I'm willing
to expend, unless somebody wants to pay me to work on this stuff).
It's late here and I want to sleep, so very briefly:
The best computational way to calculate a**x for constant a on
relatively big interval of x, like [0:1] or [-0.5:0.5] is not through
evaluation of polynomial of very high degree, but by splitting
interval into sub ranges and calculating y = Yi * a**(x-Xi) where
Yi is tabulated and may be Xi tabulated too, or may be Xi just regularly >>> spaced. For double precision and for speed/space/precision requirements
of C math library you will probably want many dozen of intervals, or
low hundreds. That allows much lower degree of poly for a**(x-Xi).
And to lower degree even further you use Chebyshev series or may be
even series derived by Remez exchange algorithm rather than Taylor
series. It means that even for a=e the second coefficient is not 1 and
likely the 1st coefficient is also not 1. So, a=e has no advantage vs
a=2. Of course, in this part of calculation a=2 also holds no
advantages vs any other base, but it has advantages in other parts of
of solution.
Different but ideologically similar reasoning applies to natural
log vs log2.
I have found over the years that 200 points seems to be best when
performing a numerical integration of a curve.-a For me, 200 points is
the point where diminishing returns has set in.-a Of course, YMMV.
Your mileage may very much vary.-a The best number of points depends on
many factors, such as the type of curve (how "wiggly" it is, whether it
has additional characteristics like monoticity that you can use, etc.), whether you are using linearly separated points or free points, how your interpolation works, what characteristics you need for the generated results, your required precision, etc.-a Characteristics of the target architecture can influence the best choice of points - bigger tables may
let you use simpler calculations, but calculations may be cheaper than
more complicated table lookup schemes.-a There is no single guideline for the number of points in such tables that can be useful in any general
sense.
I don't quite understand the use of the table Michael is describing
here, but it does not at all surprise me that practical implementations
of "pow" (and no doubt many other irrational functions) combine range- splitting and tables so that the polynomial approximations are efficient.
My own understanding here is probably on a similar level to Keith's - I
know the theoretical maths (Taylor series and all), know the difference between the theoretical infinite precision infinite series and limited precision numerical analysis, know about error analysis, basis
polynomials like Chebyshev, etc.-a But I also know there's a lot of
detail that I would have to learn or look up, that real-world speed can
have surprising differences from what you expect, that people have
figured out smart tricks to get good results faster, and that you need a great deal of experience working on this kind of code to write it well.
I don't have that experience or practical knowledge - I have to trust
those that do (like Michael).
For my own uses, I typically need things like sin functions for motor control and other such applications.-a Tables of perhaps 16 or 32 evenly spaced points, with cubic interpolation, are often fine to get the
accuracy I need in a few clock cycles on a microcontroller.-a (I don't
think I have ever needed a floating point "pow" on a microcontroller.)
On 11/08/2026 4:01 PM, Lynn McGuire wrote:
Why is there not a ipow version of pow?
ipow would return an int instead of a double.-a Or a long long int.
Thanks,
Lynn
Dear Lynn,
I can't speak for the ISO C committee, but my guess is the lack of a
multi precision library in the standard.-a If I remember Tom St Denis'
book correctly, implementing an ipow() with such a library is /trivial/
for some version of trivial.-a I just don't remember if such a function
is included in his.
In any case, I don't think an ipow() is all that useful unless there is
a multiprecision type to return the value.-a Do you disagree with that?
Mine is coming from a chemical process simulator where chemicals are
moving between the four phases of matter that we support: vapor,
hydrocarbon liquid, aqueous liquid, and solids, based on temperature and pressure.-a The tables are incredibly non-linear.
This is my people and I:
-a-a https://www.winsim.com/
Nice fact: clang++ and g++ are *much* faster than MSVC with my code.
I asked my self why is that and I had a look at the compiled code. I
do a "b * e / b == b" check. MSVC uses a division for that. g++ and
clang++ just check the overflow flag after doing the multiplication.
On 8/13/2026 4:19 AM, Johann 'Myrkraverk' Oskarsson wrote:
On 11/08/2026 4:01 PM, Lynn McGuire wrote:
Why is there not a ipow version of pow?
ipow would return an int instead of a double.-a Or a long long int.
Thanks,
Lynn
Dear Lynn,
I can't speak for the ISO C committee, but my guess is the lack of a
multi precision library in the standard.-a If I remember Tom St Denis'
book correctly, implementing an ipow() with such a library is /trivial/
for some version of trivial.-a I just don't remember if such a function
is included in his.
In any case, I don't think an ipow() is all that useful unless there is
a multiprecision type to return the value.-a Do you disagree with that?
I would rather see a standard user interface toolkit for C++ first.
https://wxwidgets.org/ is close but I have yet to try it out.
On 8/11/2026 11:26 PM, Lawrence DrCOOliveiro wrote:
On Tue, 11 Aug 2026 03:01:07 -0500, Lynn McGuire wrote:
Why is there not a ipow version of pow?
Perhaps for the same reason there arenrCOt integer log functions: itrCOs
all down to dynamic range. Logs and exponentials by their nature are
liable to cover a huge range of magnitudes in either the argument
(logarithm) or result (exponential). Integer formats in common use do
not cater for this. Whereas with floating-point -- well, itrCOs there in
the name, isnrCOt it?
This is why you calculate and return a long long int.-a Or maybe even a
128 bit int.
Lynn
On 8/13/2026 4:59 PM, Lynn McGuire wrote:
[...]
Mine is coming from a chemical process simulator where chemicals are
moving between the four phases of matter that we support: vapor,
hydrocarbon liquid, aqueous liquid, and solids, based on temperature
and pressure.-a The tables are incredibly non-linear.
This is my people and I:
-a-a-a https://www.winsim.com/
Notice any fractal growth in there?
On 12/08/2026 2:37 PM, Lynn McGuire wrote:
On 8/11/2026 11:26 PM, Lawrence DrCOOliveiro wrote:
On Tue, 11 Aug 2026 03:01:07 -0500, Lynn McGuire wrote:
Why is there not a ipow version of pow?
Perhaps for the same reason there arenrCOt integer log functions: itrCOs >>> all down to dynamic range. Logs and exponentials by their nature are
liable to cover a huge range of magnitudes in either the argument
(logarithm) or result (exponential). Integer formats in common use do
not cater for this. Whereas with floating-point -- well, itrCOs there in >>> the name, isnrCOt it?
This is why you calculate and return a long long int.-a Or maybe even a
128 bit int.
Lynn
Is there a reason you don't use a multiprecision library, such as the
one by the late Tom St Denis, in your code base?
On 14/08/2026 8:07 AM, Lynn McGuire wrote:
On 8/13/2026 4:19 AM, Johann 'Myrkraverk' Oskarsson wrote:
On 11/08/2026 4:01 PM, Lynn McGuire wrote:
Why is there not a ipow version of pow?
ipow would return an int instead of a double.-a Or a long long int.
Thanks,
Lynn
Dear Lynn,
I can't speak for the ISO C committee, but my guess is the lack of a
multi precision library in the standard.-a If I remember Tom St Denis'
book correctly, implementing an ipow() with such a library is /trivial/
for some version of trivial.-a I just don't remember if such a function
is included in his.
In any case, I don't think an ipow() is all that useful unless there is
a multiprecision type to return the value.-a Do you disagree with that?
I would rather see a standard user interface toolkit for C++ first.
Fair enough.-a I come at this discussion from comp.lang.c, and as such,
don't care what the C++ standards committee does.
https://wxwidgets.org/ is close but I have yet to try it out.
I just treat IUP as an /industry standard/ interface toolkit for C.
-a https://iup.sourceforge.net/
And I believe that would require a different standards committee than
-- what was it? WG14 -- to include in the ISO standards collection, as
it's still targetting C89 if I'm not mistaken, and doesn't keep up with
WG14 at all.
Perhaps just best to standardize it with A.N.S.I. in the United States,
if at all?-a I admit ignorance on how much paperwork that is, and I'd certainly include PUC Rio in such discussions, somehow.-a Even if they're also not in the United States.
Best wishes, and happy interfacing with IUP!
On 8/13/2026 10:22 PM, Johann 'Myrkraverk' Oskarsson wrote:
On 12/08/2026 2:37 PM, Lynn McGuire wrote:
On 8/11/2026 11:26 PM, Lawrence DrCOOliveiro wrote:
On Tue, 11 Aug 2026 03:01:07 -0500, Lynn McGuire wrote:
Why is there not a ipow version of pow?
Perhaps for the same reason there arenrCOt integer log functions: itrCOs >>>> all down to dynamic range. Logs and exponentials by their nature are
liable to cover a huge range of magnitudes in either the argument
(logarithm) or result (exponential). Integer formats in common use do
not cater for this. Whereas with floating-point -- well, itrCOs there in >>>> the name, isnrCOt it?
This is why you calculate and return a long long int.-a Or maybe even
a 128 bit int.
Lynn
Is there a reason you don't use a multiprecision library, such as the
one by the late Tom St Denis, in your code base?
I am converting from Fortran 77 to C++.-a The last thing I want to do is introduce more new features in the code.
Lynn
On 8/13/2026 1:38 AM, David Brown wrote:[...]
On 12/08/2026 23:49, Lynn McGuire wrote:
[...]I have found over the years that 200 points seems to be best when
performing a numerical integration of a curve.-a For me, 200 points is
the point where diminishing returns has set in.-a Of course, YMMV.
Your mileage may very much vary.-a The best number of points depends on
many factors, such as the type of curve (how "wiggly" it is, whether
it has additional characteristics like monoticity that you can use,
etc.), whether you are using linearly separated points or free points,
how your interpolation works, what characteristics you need for the
generated results, your required precision, etc.-a Characteristics of
the target architecture can influence the best choice of points -
bigger tables may let you use simpler calculations, but calculations
may be cheaper than more complicated table lookup schemes.-a There is
no single guideline for the number of points in such tables that can
be useful in any general sense.
Mine is coming from a chemical process simulator where chemicals are
moving between the four phases of matter that we support: vapor,
hydrocarbon liquid, aqueous liquid, and solids, based on temperature and pressure.-a The tables are incredibly non-linear.
On 14/08/2026 2:00 PM, Lynn McGuire wrote:
On 8/13/2026 10:22 PM, Johann 'Myrkraverk' Oskarsson wrote:
On 12/08/2026 2:37 PM, Lynn McGuire wrote:
On 8/11/2026 11:26 PM, Lawrence DrCOOliveiro wrote:
On Tue, 11 Aug 2026 03:01:07 -0500, Lynn McGuire wrote:
Why is there not a ipow version of pow?
Perhaps for the same reason there arenrCOt integer log functions: itrCOs >>>>> all down to dynamic range. Logs and exponentials by their nature are >>>>> liable to cover a huge range of magnitudes in either the argument
(logarithm) or result (exponential). Integer formats in common use do >>>>> not cater for this. Whereas with floating-point -- well, itrCOs there in >>>>> the name, isnrCOt it?
This is why you calculate and return a long long int.-a Or maybe even >>>> a 128 bit int.
Lynn
Is there a reason you don't use a multiprecision library, such as the
one by the late Tom St Denis, in your code base?
I am converting from Fortran 77 to C++.-a The last thing I want to do
is introduce more new features in the code.
Lynn
Fair enough.-a If you change your mind -- and for other people interested
in the subject -- you can look at chapter seven of Tom's book.-a Of
course, you won't need to read the details of the implementation just to
use the library, which is available somewhere on GitHub.
Have a nice day!
On 14/08/2026 2:00 PM, Lynn McGuire wrote:
On 8/13/2026 10:22 PM, Johann 'Myrkraverk' Oskarsson wrote:
On 12/08/2026 2:37 PM, Lynn McGuire wrote:
On 8/11/2026 11:26 PM, Lawrence DrCOOliveiro wrote:
On Tue, 11 Aug 2026 03:01:07 -0500, Lynn McGuire wrote:
Why is there not a ipow version of pow?
Perhaps for the same reason there arenrCOt integer log functions: itrCOs >>>>> all down to dynamic range. Logs and exponentials by their nature are >>>>> liable to cover a huge range of magnitudes in either the argument
(logarithm) or result (exponential). Integer formats in common use do >>>>> not cater for this. Whereas with floating-point -- well, itrCOs there in >>>>> the name, isnrCOt it?
This is why you calculate and return a long long int.-a Or maybe even >>>> a 128 bit int.
Lynn
Is there a reason you don't use a multiprecision library, such as the
one by the late Tom St Denis, in your code base?
I am converting from Fortran 77 to C++.-a The last thing I want to do
is introduce more new features in the code.
Lynn
Fair enough.-a If you change your mind -- and for other people interested
in the subject -- you can look at chapter seven of Tom's book.-a Of
course, you won't need to read the details of the implementation just to
use the library, which is available somewhere on GitHub.
Have a nice day!
On 8/13/2026 8:51 PM, Chris M. Thomasson wrote:Let me clarify... Do you make renders of a simulation? If so, do some of
On 8/13/2026 4:59 PM, Lynn McGuire wrote:
[...]
Mine is coming from a chemical process simulator where chemicals are
moving between the four phases of matter that we support: vapor,
hydrocarbon liquid, aqueous liquid, and solids, based on temperature
and pressure.-a The tables are incredibly non-linear.
This is my people and I:
-a-a-a https://www.winsim.com/
Notice any fractal growth in there?
We don't do that.
On 14/08/2026 01:59, Lynn McGuire wrote:
On 8/13/2026 1:38 AM, David Brown wrote:[...]
On 12/08/2026 23:49, Lynn McGuire wrote:
[...]I have found over the years that 200 points seems to be best when
performing a numerical integration of a curve.-a For me, 200 points
is the point where diminishing returns has set in.-a Of course, YMMV.
Your mileage may very much vary.-a The best number of points depends
on many factors, such as the type of curve (how "wiggly" it is,
whether it has additional characteristics like monoticity that you
can use, etc.), whether you are using linearly separated points or
free points, how your interpolation works, what characteristics you
need for the generated results, your required precision, etc.
Characteristics of the target architecture can influence the best
choice of points - bigger tables may let you use simpler
calculations, but calculations may be cheaper than more complicated
table lookup schemes.-a There is no single guideline for the number of
points in such tables that can be useful in any general sense.
Mine is coming from a chemical process simulator where chemicals are
moving between the four phases of matter that we support: vapor,
hydrocarbon liquid, aqueous liquid, and solids, based on temperature
and pressure.-a The tables are incredibly non-linear.
Sure, for particularly "wiggly" curves, or paths with discontinuities,
you need a lot more information to describe them - that means more
points, or more complex interpolation between them.-a (I am using "interpolation" in a general sense here, including any kind of
polynomial approximation - not specifically simple linear
interpolation.)-a I have no doubt that you need more points than I need - there is no universal rule of thumb for table size that suits a range of applications.
On 8/13/2026 11:47 PM, Johann 'Myrkraverk' Oskarsson wrote:
On 14/08/2026 2:00 PM, Lynn McGuire wrote:
On 8/13/2026 10:22 PM, Johann 'Myrkraverk' Oskarsson wrote:
On 12/08/2026 2:37 PM, Lynn McGuire wrote:
On 8/11/2026 11:26 PM, Lawrence DrCOOliveiro wrote:
On Tue, 11 Aug 2026 03:01:07 -0500, Lynn McGuire wrote:
Why is there not a ipow version of pow?
Perhaps for the same reason there arenrCOt integer log functions: itrCOs >>>>>> all down to dynamic range. Logs and exponentials by their nature are >>>>>> liable to cover a huge range of magnitudes in either the argument
(logarithm) or result (exponential). Integer formats in common use do >>>>>> not cater for this. Whereas with floating-point -- well, itrCOs
there in
the name, isnrCOt it?
This is why you calculate and return a long long int.-a Or maybe
even a 128 bit int.
Lynn
Is there a reason you don't use a multiprecision library, such as the
one by the late Tom St Denis, in your code base?
I am converting from Fortran 77 to C++.-a The last thing I want to do
is introduce more new features in the code.
Lynn
Fair enough.-a If you change your mind -- and for other people interested
in the subject -- you can look at chapter seven of Tom's book.-a Of
course, you won't need to read the details of the implementation just to
use the library, which is available somewhere on GitHub.
Have a nice day!
The have a nice day, and the -- are tell tale signs of an AI writing
your responses?
On 15/08/2026 3:03 AM, Chris M. Thomasson wrote:
On 8/13/2026 11:47 PM, Johann 'Myrkraverk' Oskarsson wrote:
On 14/08/2026 2:00 PM, Lynn McGuire wrote:
On 8/13/2026 10:22 PM, Johann 'Myrkraverk' Oskarsson wrote:
On 12/08/2026 2:37 PM, Lynn McGuire wrote:
On 8/11/2026 11:26 PM, Lawrence DrCOOliveiro wrote:
On Tue, 11 Aug 2026 03:01:07 -0500, Lynn McGuire wrote:
Why is there not a ipow version of pow?
Perhaps for the same reason there arenrCOt integer log functions: itrCOs
all down to dynamic range. Logs and exponentials by their nature are >>>>>>> liable to cover a huge range of magnitudes in either the argument >>>>>>> (logarithm) or result (exponential). Integer formats in common
use do
not cater for this. Whereas with floating-point -- well, itrCOs >>>>>>> there in
the name, isnrCOt it?
This is why you calculate and return a long long int.-a Or maybe
even a 128 bit int.
Lynn
Is there a reason you don't use a multiprecision library, such as the >>>>> one by the late Tom St Denis, in your code base?
I am converting from Fortran 77 to C++.-a The last thing I want to do >>>> is introduce more new features in the code.
Lynn
Fair enough.-a If you change your mind -- and for other people interested >>> in the subject -- you can look at chapter seven of Tom's book.-a Of
course, you won't need to read the details of the implementation just to >>> use the library, which is available somewhere on GitHub.
Have a nice day!
The have a nice day, and the -- are tell tale signs of an AI writing
your responses?
Is the expression /tell tale/ a sign of you insisting I use A.I. when
you know I don't?-a Do you get off of writing tall tales?-a Do you post
in alt.sex.erotica.moderated?-a Are you the moderator?
On 8/14/2026 12:51 PM, Johann 'Myrkraverk' Oskarsson wrote:
On 15/08/2026 3:03 AM, Chris M. Thomasson wrote:
On 8/13/2026 11:47 PM, Johann 'Myrkraverk' Oskarsson wrote:
On 14/08/2026 2:00 PM, Lynn McGuire wrote:
On 8/13/2026 10:22 PM, Johann 'Myrkraverk' Oskarsson wrote:
On 12/08/2026 2:37 PM, Lynn McGuire wrote:
On 8/11/2026 11:26 PM, Lawrence DrCOOliveiro wrote:
On Tue, 11 Aug 2026 03:01:07 -0500, Lynn McGuire wrote:
Why is there not a ipow version of pow?
Perhaps for the same reason there arenrCOt integer log functions: >>>>>>>> itrCOs
all down to dynamic range. Logs and exponentials by their nature >>>>>>>> are
liable to cover a huge range of magnitudes in either the argument >>>>>>>> (logarithm) or result (exponential). Integer formats in common >>>>>>>> use do
not cater for this. Whereas with floating-point -- well, itrCOs >>>>>>>> there in
the name, isnrCOt it?
This is why you calculate and return a long long int.-a Or maybe >>>>>>> even a 128 bit int.
Lynn
Is there a reason you don't use a multiprecision library, such as the >>>>>> one by the late Tom St Denis, in your code base?
I am converting from Fortran 77 to C++.-a The last thing I want to
do is introduce more new features in the code.
Lynn
Fair enough.-a If you change your mind -- and for other people
interested
in the subject -- you can look at chapter seven of Tom's book.-a Of
course, you won't need to read the details of the implementation
just to
use the library, which is available somewhere on GitHub.
Have a nice day!
The have a nice day, and the -- are tell tale signs of an AI writing
your responses?
Is the expression /tell tale/ a sign of you insisting I use A.I. when
you know I don't?-a Do you get off of writing tall tales?-a Do you post
in alt.sex.erotica.moderated?-a Are you the moderator?
Are you using AI to help write your responses? There are some flags.
On 8/14/2026 1:01 PM, Johann 'Myrkraverk' Oskarsson wrote:
[...]
You're completely free to capture the flag on your own.-a You'll just
have to write the game in C, because I'm coming at this from comp.lang.
c.-a And not comp.lang.c++.
I still type my replies by hand, but you're unable to do so, so you must
dictate to Siri, which sends the request to Copilot, which hopefully
uses the most expensive Usenet service available for your posts.-a I
mean, why stop at paying both the fruit vendor for Siri, and Microsoft
for Copilot, and not get the world's best and greatest Usenet provider?
Happy posting on Usenet with Siri and Copilot!
Huh. So, you are an "ass" all by yourself?
You're completely free to capture the flag on your own.-a You'll just
have to write the game in C, because I'm coming at this from comp.lang.
c.-a And not comp.lang.c++.
I still type my replies by hand, but you're unable to do so, so you must dictate to Siri, which sends the request to Copilot, which hopefully
uses the most expensive Usenet service available for your posts.-a I
mean, why stop at paying both the fruit vendor for Siri, and Microsoft
for Copilot, and not get the world's best and greatest Usenet provider?
Happy posting on Usenet with Siri and Copilot!
On 8/13/2026 10:58 PM, Lynn McGuire wrote:
On 8/13/2026 8:51 PM, Chris M. Thomasson wrote:Let me clarify... Do you make renders of a simulation? If so, do some of them look fractal?
On 8/13/2026 4:59 PM, Lynn McGuire wrote:
[...]
Mine is coming from a chemical process simulator where chemicals are
moving between the four phases of matter that we support: vapor,
hydrocarbon liquid, aqueous liquid, and solids, based on temperature
and pressure.-a The tables are incredibly non-linear.
This is my people and I:
-a-a-a https://www.winsim.com/
Notice any fractal growth in there?
We don't do that.
On 8/14/2026 1:27 PM, Chris M. Thomasson wrote:
On 8/14/2026 1:01 PM, Johann 'Myrkraverk' Oskarsson wrote:
[...]
You're completely free to capture the flag on your own.-a You'll just
have to write the game in C, because I'm coming at this from comp.lang.
c.-a And not comp.lang.c++.
I still type my replies by hand, but you're unable to do so, so you must >>> dictate to Siri, which sends the request to Copilot, which hopefully
uses the most expensive Usenet service available for your posts.-a I
mean, why stop at paying both the fruit vendor for Siri, and Microsoft
for Copilot, and not get the world's best and greatest Usenet provider?
Happy posting on Usenet with Siri and Copilot!
Huh. So, you are an "ass" all by yourself?
The -- and the final "have a happy ..." aspects reek of AI all over...
On 8/14/2026 2:08 PM, Chris M. Thomasson wrote:Ahhhh! So, you are not making any animations of the processes. Okay. But
On 8/13/2026 10:58 PM, Lynn McGuire wrote:
On 8/13/2026 8:51 PM, Chris M. Thomasson wrote:Let me clarify... Do you make renders of a simulation? If so, do some
On 8/13/2026 4:59 PM, Lynn McGuire wrote:
[...]
Mine is coming from a chemical process simulator where chemicals
are moving between the four phases of matter that we support:
vapor, hydrocarbon liquid, aqueous liquid, and solids, based on
temperature and pressure.-a The tables are incredibly non-linear.
This is my people and I:
-a-a-a https://www.winsim.com/
Notice any fractal growth in there?
We don't do that.
of them look fractal?
In short, no.-a We have a diagrammatic user interface that allows our
users to build a diagram of a chemical process flow diagram such as a refinery, a natural gas plan, a pipeline with compressor stations, or a chemical plant.
-a-a https://www.winsim.com/screenshots.html
And we have a calculation engine that takes a textual version of that diagram and solves it thermodynamically.-a If, it can be solved as not
all chemical processes can be solved due to constraints or violation of
the laws of thermodynamics.
On 8/14/2026 1:48 PM, Lynn McGuire wrote:
On 8/14/2026 2:08 PM, Chris M. Thomasson wrote:Ahhhh! So, you are not making any animations of the processes. Okay. But
On 8/13/2026 10:58 PM, Lynn McGuire wrote:
On 8/13/2026 8:51 PM, Chris M. Thomasson wrote:Let me clarify... Do you make renders of a simulation? If so, do some
On 8/13/2026 4:59 PM, Lynn McGuire wrote:
[...]
Mine is coming from a chemical process simulator where chemicals
are moving between the four phases of matter that we support:
vapor, hydrocarbon liquid, aqueous liquid, and solids, based on
temperature and pressure.-a The tables are incredibly non-linear.
This is my people and I:
-a-a-a https://www.winsim.com/
Notice any fractal growth in there?
We don't do that.
of them look fractal?
In short, no.-a We have a diagrammatic user interface that allows our
users to build a diagram of a chemical process flow diagram such as a
refinery, a natural gas plan, a pipeline with compressor stations, or
a chemical plant.
-a-a-a https://www.winsim.com/screenshots.html
And we have a calculation engine that takes a textual version of that
diagram and solves it thermodynamically.-a If, it can be solved as not
all chemical processes can be solved due to constraints or violation
of the laws of thermodynamics.
you have the data to do so...
Fwiw, I bet you already have the data to make one of my 2d examples here:
https://youtu.be/YS-tyDJVy4M
On 8/14/2026 3:51 PM, Chris M. Thomasson wrote:
On 8/14/2026 1:48 PM, Lynn McGuire wrote:
On 8/14/2026 2:08 PM, Chris M. Thomasson wrote:Ahhhh! So, you are not making any animations of the processes. Okay.
On 8/13/2026 10:58 PM, Lynn McGuire wrote:
On 8/13/2026 8:51 PM, Chris M. Thomasson wrote:Let me clarify... Do you make renders of a simulation? If so, do
On 8/13/2026 4:59 PM, Lynn McGuire wrote:
[...]
Mine is coming from a chemical process simulator where chemicals >>>>>>> are moving between the four phases of matter that we support:
vapor, hydrocarbon liquid, aqueous liquid, and solids, based on >>>>>>> temperature and pressure.-a The tables are incredibly non-linear. >>>>>>>
This is my people and I:
-a-a-a https://www.winsim.com/
Notice any fractal growth in there?
We don't do that.
some of them look fractal?
In short, no.-a We have a diagrammatic user interface that allows our
users to build a diagram of a chemical process flow diagram such as a
refinery, a natural gas plan, a pipeline with compressor stations, or
a chemical plant.
-a-a-a https://www.winsim.com/screenshots.html
And we have a calculation engine that takes a textual version of that
diagram and solves it thermodynamically.-a If, it can be solved as not
all chemical processes can be solved due to constraints or violation
of the laws of thermodynamics.
But you have the data to do so...
Fwiw, I bet you already have the data to make one of my 2d examples here:
https://youtu.be/YS-tyDJVy4M
Actually, I do make an animation of the process simulation diagram
(PSD).
If the users run a dynamic (time sensitive) version of the
simulation, the user can roll through their displayed results on the
various sheets of the PSD using their time breaks.
Deal with it, you fucking cuck!
On 8/14/2026 2:40 PM, Lynn McGuire wrote:...
On 8/14/2026 3:51 PM, Chris M. Thomasson wrote:
On 8/14/2026 1:48 PM, Lynn McGuire wrote:
On 8/14/2026 2:08 PM, Chris M. Thomasson wrote:Ahhhh! So, you are not making any animations of the processes. Okay.
On 8/13/2026 10:58 PM, Lynn McGuire wrote:
On 8/13/2026 8:51 PM, Chris M. Thomasson wrote:Let me clarify... Do you make renders of a simulation? If so, do
On 8/13/2026 4:59 PM, Lynn McGuire wrote:
[...]
Mine is coming from a chemical process simulator where chemicals >>>>>>>> are moving between the four phases of matter that we support: >>>>>>>> vapor, hydrocarbon liquid, aqueous liquid, and solids, based on >>>>>>>> temperature and pressure.-a The tables are incredibly non-linear. >>>>>>>>
This is my people and I:
-a-a-a https://www.winsim.com/
Notice any fractal growth in there?
We don't do that.
some of them look fractal?
In short, no.-a We have a diagrammatic user interface that allows our >>>> users to build a diagram of a chemical process flow diagram such as
a refinery, a natural gas plan, a pipeline with compressor stations,
or a chemical plant.
-a-a-a https://www.winsim.com/screenshots.html
And we have a calculation engine that takes a textual version of
that diagram and solves it thermodynamically.-a If, it can be solved
as not all chemical processes can be solved due to constraints or
violation of the laws of thermodynamics.
But you have the data to do so...
Fwiw, I bet you already have the data to make one of my 2d examples
here:
https://youtu.be/YS-tyDJVy4M
Actually, I do make an animation of the process simulation diagram (PSD).
Can you give me a link to some screenshots so I can get on the same
page? Thanks. Are you almost done with your Fortran port?
On 8/14/2026 9:24 PM, Chris M. Thomasson wrote:
On 8/14/2026 2:40 PM, Lynn McGuire wrote:...
On 8/14/2026 3:51 PM, Chris M. Thomasson wrote:
On 8/14/2026 1:48 PM, Lynn McGuire wrote:
On 8/14/2026 2:08 PM, Chris M. Thomasson wrote:Ahhhh! So, you are not making any animations of the processes. Okay.
On 8/13/2026 10:58 PM, Lynn McGuire wrote:
On 8/13/2026 8:51 PM, Chris M. Thomasson wrote:Let me clarify... Do you make renders of a simulation? If so, do
On 8/13/2026 4:59 PM, Lynn McGuire wrote:
[...]
Mine is coming from a chemical process simulator where
chemicals are moving between the four phases of matter that we >>>>>>>>> support: vapor, hydrocarbon liquid, aqueous liquid, and solids, >>>>>>>>> based on temperature and pressure.-a The tables are incredibly >>>>>>>>> non-linear.
This is my people and I:
-a-a-a https://www.winsim.com/
Notice any fractal growth in there?
We don't do that.
some of them look fractal?
In short, no.-a We have a diagrammatic user interface that allows
our users to build a diagram of a chemical process flow diagram
such as a refinery, a natural gas plan, a pipeline with compressor
stations, or a chemical plant.
-a-a-a https://www.winsim.com/screenshots.html
And we have a calculation engine that takes a textual version of
that diagram and solves it thermodynamically.-a If, it can be solved >>>>> as not all chemical processes can be solved due to constraints or
violation of the laws of thermodynamics.
But you have the data to do so...
Fwiw, I bet you already have the data to make one of my 2d examples
here:
https://youtu.be/YS-tyDJVy4M
Actually, I do make an animation of the process simulation diagram
(PSD).
Can you give me a link to some screenshots so I can get on the same
page? Thanks. Are you almost done with your Fortran port?
https://www.winsim.com/screenshots.html
I am about 1/3rd of the way done with my 800,000 lines of F77 code to C+
+ code.-a My custom version of F2C is doing about 60 to 70% of the work.
I am equating the task as equivalent to translating about ten long engineering books from German to French.-a Lots of idioms and basic incompatibilities that have to be ironed out.
I was shooting for the end of 2026 but that ship has sailed.-a Maybe
middle of 2027.-a Then I have to port to x64 but the port should be easy
(he says with the ship sitting in ten feet of mud in the harbor).
Lynn
On 8/14/2026 9:24 PM, Chris M. Thomasson wrote:
On 8/14/2026 2:40 PM, Lynn McGuire wrote:...
On 8/14/2026 3:51 PM, Chris M. Thomasson wrote:
On 8/14/2026 1:48 PM, Lynn McGuire wrote:
On 8/14/2026 2:08 PM, Chris M. Thomasson wrote:Ahhhh! So, you are not making any animations of the processes. Okay.
On 8/13/2026 10:58 PM, Lynn McGuire wrote:
On 8/13/2026 8:51 PM, Chris M. Thomasson wrote:Let me clarify... Do you make renders of a simulation? If so, do
On 8/13/2026 4:59 PM, Lynn McGuire wrote:
[...]
Mine is coming from a chemical process simulator where
chemicals are moving between the four phases of matter that we >>>>>>>>> support: vapor, hydrocarbon liquid, aqueous liquid, and solids, >>>>>>>>> based on temperature and pressure. The tables are incredibly >>>>>>>>> non-linear.
This is my people and I:
https://www.winsim.com/
Notice any fractal growth in there?
We don't do that.
some of them look fractal?
In short, no. We have a diagrammatic user interface that allows
our users to build a diagram of a chemical process flow diagram
such as a refinery, a natural gas plan, a pipeline with compressor
stations, or a chemical plant.
https://www.winsim.com/screenshots.html
And we have a calculation engine that takes a textual version of
that diagram and solves it thermodynamically. If, it can be solved
as not all chemical processes can be solved due to constraints or
violation of the laws of thermodynamics.
But you have the data to do so...
Fwiw, I bet you already have the data to make one of my 2d examples
here:
https://youtu.be/YS-tyDJVy4M
Actually, I do make an animation of the process simulation diagram
(PSD).
Can you give me a link to some screenshots so I can get on the same
page? Thanks. Are you almost done with your Fortran port?
https://www.winsim.com/screenshots.html
I am about 1/3rd of the way done with my 800,000 lines of F77 code to
C++ code. My custom version of F2C is doing about 60 to 70% of the
work. I am equating the task as equivalent to translating about ten
long engineering books from German to French. Lots of idioms and basic incompatibilities that have to be ironed out.
I was shooting for the end of 2026 but that ship has sailed. Maybe
middle of 2027. Then I have to port to x64 but the port should be easy
(he says with the ship sitting in ten feet of mud in the harbor).
Lynn
Long story short such an endeavor is perceived to be a store of
great _value_, and such porting effort is quite a study of both
the numerical methods, which as usually approximations need
their error-bounds modeled, like Runge-Kutta for example after
Gregory & Coates as Newton's, or about Leontief and so on,
numerical methods and linear systems and linear solvers,
then with regards to standard and empirical units, which are
not necessarily the same and where regimes of effect are
according to their own units, good luck with that, it sounds
like something vital to the real-world economy.
BTW, in Smalltalk you can return any type of object from a method.
But if the caller got a weird object back, it was a place of
confusion and often a crash as the expected object type was not the
actual object type.
I way prefer strongly typed languages now.
So, all objects had to have a common set of methods (read, write,
print, add, etc) to keep weird crashes from happening. I ended up
putting all methods at an object and the base object too. Our base
object had hundreds of methods to handle weird cases.
I would rather see a standard user interface toolkit for C++ first.
| Sysop: | Amessyroom |
|---|---|
| Location: | Fayetteville, NC |
| Users: | 74 |
| Nodes: | 6 (0 / 6) |
| Uptime: | 51:09:49 |
| Calls: | 1,100 |
| Files: | 1,339 |
| Messages: | 276,012 |