Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #124609 > unrolled thread

why is there not a ipow version of pow?

Started byLynn McGuire <lynnmcguire5@gmail.com>
First post2026-08-11 03:01 -0500
Last post2026-08-18 11:32 +0200
Articles 20 on this page of 132 — 15 participants

Back to article view | Back to comp.lang.c++


Contents

  why is there not a ipow version of pow? Lynn McGuire <lynnmcguire5@gmail.com> - 2026-08-11 03:01 -0500
    Re: why is there not a ipow version of pow? Bonita Montero <Bonita.Montero@gmail.com> - 2026-08-11 13:11 +0200
      Re: why is there not a ipow version of pow? bart <bc@freeuk.com> - 2026-08-11 12:45 +0100
        Re: why is there not a ipow version of pow? Bonita Montero <Bonita.Montero@gmail.com> - 2026-08-11 14:34 +0200
        Re: why is there not a ipow version of pow? Bonita Montero <Bonita.Montero@gmail.com> - 2026-08-11 14:55 +0200
          Re: why is there not a ipow version of pow? David Brown <david.brown@hesbynett.no> - 2026-08-11 15:19 +0200
            Re: why is there not a ipow version of pow? Bonita Montero <Bonita.Montero@gmail.com> - 2026-08-11 15:27 +0200
              Re: why is there not a ipow version of pow? David Brown <david.brown@hesbynett.no> - 2026-08-11 16:08 +0200
                Re: why is there not a ipow version of pow? Bonita Montero <Bonita.Montero@gmail.com> - 2026-08-11 16:18 +0200
                  Re: why is there not a ipow version of pow? David Brown <david.brown@hesbynett.no> - 2026-08-11 17:11 +0200
                    Re: why is there not a ipow version of pow? Bonita Montero <Bonita.Montero@gmail.com> - 2026-08-11 17:20 +0200
                      Re: why is there not a ipow version of pow? David Brown <david.brown@hesbynett.no> - 2026-08-11 17:32 +0200
                        Re: why is there not a ipow version of pow? Bonita Montero <Bonita.Montero@gmail.com> - 2026-08-11 17:39 +0200
                          Re: why is there not a ipow version of pow? David Brown <david.brown@hesbynett.no> - 2026-08-11 18:33 +0200
                            Re: why is there not a ipow version of pow? Bonita Montero <Bonita.Montero@gmail.com> - 2026-08-11 18:39 +0200
                            Re: why is there not a ipow version of pow? Michael S <already5chosen@yahoo.com> - 2026-08-11 23:31 +0300
                        Re: why is there not a ipow version of pow? James Kuyper <jameskuyper@alumni.caltech.edu> - 2026-08-11 11:46 -0400
                          Re: why is there not a ipow version of pow? David Brown <david.brown@hesbynett.no> - 2026-08-11 18:35 +0200
                        Re: why is there not a ipow version of pow? antispam@fricas.org (Waldek Hebisch) - 2026-08-11 22:53 +0000
                          Re: why is there not a ipow version of pow? David Brown <david.brown@hesbynett.no> - 2026-08-12 10:08 +0200
                            Re: why is there not a ipow version of pow? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2026-08-12 03:58 -0700
                              Re: why is there not a ipow version of pow? David Brown <david.brown@hesbynett.no> - 2026-08-12 13:31 +0200
                              Re: why is there not a ipow version of pow? Michael S <already5chosen@yahoo.com> - 2026-08-12 22:43 +0300
                                Re: why is there not a ipow version of pow? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2026-08-12 13:44 -0700
                                  Re: why is there not a ipow version of pow? Michael S <already5chosen@yahoo.com> - 2026-08-13 00:24 +0300
                                    Re: why is there not a ipow version of pow? Lynn McGuire <lynnmcguire5@gmail.com> - 2026-08-12 16:49 -0500
                                      Re: why is there not a ipow version of pow? David Brown <david.brown@hesbynett.no> - 2026-08-13 08:38 +0200
                                        Re: why is there not a ipow version of pow? Lynn McGuire <lynnmcguire5@gmail.com> - 2026-08-13 18:59 -0500
                                          Re: why is there not a ipow version of pow? "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2026-08-13 18:51 -0700
                                            Re: why is there not a ipow version of pow? Lynn McGuire <lynnmcguire5@gmail.com> - 2026-08-14 00:58 -0500
                                              Re: why is there not a ipow version of pow? "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2026-08-14 12:08 -0700
                                                Re: why is there not a ipow version of pow? Lynn McGuire <lynnmcguire5@gmail.com> - 2026-08-14 15:48 -0500
                                                  Re: why is there not a ipow version of pow? "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2026-08-14 13:51 -0700
                                                    Re: why is there not a ipow version of pow? Lynn McGuire <lynnmcguire5@gmail.com> - 2026-08-14 16:40 -0500
                                                      Re: why is there not a ipow version of pow? "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2026-08-14 19:24 -0700
                                                        Re: why is there not a ipow version of pow? Lynn McGuire <lynnmcguire5@gmail.com> - 2026-08-14 22:51 -0500
                                                          Re: why is there not a ipow version of pow? "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2026-08-14 22:33 -0700
                                                          Re: why is there not a ipow version of pow? Ross Finlayson <ross.a.finlayson@gmail.com> - 2026-08-15 10:40 -0700
                                                            Re: why is there not a ipow version of pow? "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2026-08-15 11:41 -0700
                                                            Re: why is there not a ipow version of pow? Lynn McGuire <lynnmcguire5@gmail.com> - 2026-08-17 14:48 -0500
                                                      Re: why is there not a ipow version of pow? "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2026-08-16 14:58 -0700
                                          Re: why is there not a ipow version of pow? David Brown <david.brown@hesbynett.no> - 2026-08-14 08:57 +0200
                                            Re: why is there not a ipow version of pow? "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2026-08-14 12:46 -0700
                                  Re: why is there not a ipow version of pow? James Kuyper <jameskuyper@alumni.caltech.edu> - 2026-08-13 12:59 -0400
                            Re: why is there not a ipow version of pow? antispam@fricas.org (Waldek Hebisch) - 2026-08-12 20:23 +0000
                      Re: why is there not a ipow version of pow? scott@slp53.sl.home (Scott Lurndal) - 2026-08-11 18:19 +0000
                        Re: why is there not a ipow version of pow? Bonita Montero <Bonita.Montero@gmail.com> - 2026-08-11 20:21 +0200
                          Re: why is there not a ipow version of pow? scott@slp53.sl.home (Scott Lurndal) - 2026-08-11 21:10 +0000
                            Re: why is there not a ipow version of pow? Michael S <already5chosen@yahoo.com> - 2026-08-12 00:42 +0300
                            Re: why is there not a ipow version of pow? Bonita Montero <Bonita.Montero@gmail.com> - 2026-08-12 06:41 +0200
                              Re: why is there not a ipow version of pow? scott@slp53.sl.home (Scott Lurndal) - 2026-08-12 14:19 +0000
                                Re: why is there not a ipow version of pow? Bonita Montero <Bonita.Montero@gmail.com> - 2026-08-12 16:56 +0200
                                  Re: why is there not a ipow version of pow? scott@slp53.sl.home (Scott Lurndal) - 2026-08-12 15:32 +0000
                              Re: why is there not a ipow version of pow? Michael S <already5chosen@yahoo.com> - 2026-08-12 22:05 +0300
                                Re: why is there not a ipow version of pow? Paul <nospam@needed.invalid> - 2026-08-12 19:09 -0400
                      Re: why is there not a ipow version of pow? Michael S <already5chosen@yahoo.com> - 2026-08-11 21:58 +0300
                  Re: why is there not a ipow version of pow? Ross Finlayson <ross.a.finlayson@gmail.com> - 2026-08-11 21:44 -0700
                Re: why is there not a ipow version of pow? bart <bc@freeuk.com> - 2026-08-11 15:45 +0100
                  Re: why is there not a ipow version of pow? Bonita Montero <Bonita.Montero@gmail.com> - 2026-08-11 16:56 +0200
                    Re: why is there not a ipow version of pow? David Brown <david.brown@hesbynett.no> - 2026-08-11 17:23 +0200
                      Re: why is there not a ipow version of pow? Bonita Montero <Bonita.Montero@gmail.com> - 2026-08-11 17:24 +0200
                    Re: why is there not a ipow version of pow? bart <bc@freeuk.com> - 2026-08-11 16:23 +0100
                      Re: why is there not a ipow version of pow? Bonita Montero <Bonita.Montero@gmail.com> - 2026-08-11 17:26 +0200
                      Re: why is there not a ipow version of pow? Bonita Montero <Bonita.Montero@gmail.com> - 2026-08-11 17:54 +0200
                      Re: why is there not a ipow version of pow? Bonita Montero <Bonita.Montero@gmail.com> - 2026-08-11 18:40 +0200
                        Re: why is there not a ipow version of pow? Bonita Montero <Bonita.Montero@gmail.com> - 2026-08-12 08:49 +0200
                          Re: why is there not a ipow version of pow? Paul <nospam@needed.invalid> - 2026-08-12 09:11 -0400
                            Re: why is there not a ipow version of pow? Bonita Montero <Bonita.Montero@gmail.com> - 2026-08-12 16:05 +0200
                              Re: why is there not a ipow version of pow? "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2026-08-12 12:40 -0700
                                Re: why is there not a ipow version of pow? Bonita Montero <Bonita.Montero@gmail.com> - 2026-08-13 15:46 +0200
                                  Re: why is there not a ipow version of pow? "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2026-08-13 14:28 -0700
                      Re: why is there not a ipow version of pow? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2026-08-11 16:20 -0700
                    Re: why is there not a ipow version of pow? bart <bc@freeuk.com> - 2026-08-11 18:43 +0100
                      Re: why is there not a ipow version of pow? Bonita Montero <Bonita.Montero@gmail.com> - 2026-08-11 19:56 +0200
                        Re: why is there not a ipow version of pow? bart <bc@freeuk.com> - 2026-08-11 20:41 +0100
                          Re: why is there not a ipow version of pow? Bonita Montero <Bonita.Montero@gmail.com> - 2026-08-12 06:42 +0200
                          Re: why is there not a ipow version of pow? David Brown <david.brown@hesbynett.no> - 2026-08-12 10:23 +0200
                      Re: why is there not a ipow version of pow? Bonita Montero <Bonita.Montero@gmail.com> - 2026-08-11 20:24 +0200
                        Re: why is there not a ipow version of pow? bart <bc@freeuk.com> - 2026-08-11 20:27 +0100
                          Re: why is there not a ipow version of pow? Bonita Montero <Bonita.Montero@gmail.com> - 2026-08-12 06:45 +0200
                  Re: why is there not a ipow version of pow? David Brown <david.brown@hesbynett.no> - 2026-08-11 17:16 +0200
        Re: why is there not a ipow version of pow? David Brown <david.brown@hesbynett.no> - 2026-08-11 15:17 +0200
          Re: why is there not a ipow version of pow? Bonita Montero <Bonita.Montero@gmail.com> - 2026-08-11 15:28 +0200
            Re: why is there not a ipow version of pow? David Brown <david.brown@hesbynett.no> - 2026-08-11 16:43 +0200
              Re: why is there not a ipow version of pow? Bonita Montero <Bonita.Montero@gmail.com> - 2026-08-11 16:47 +0200
                Re: why is there not a ipow version of pow? David Brown <david.brown@hesbynett.no> - 2026-08-11 17:24 +0200
      Re: why is there not a ipow version of pow? Paul <nospam@needed.invalid> - 2026-08-11 09:36 -0400
        Re: why is there not a ipow version of pow? Lynn McGuire <lynnmcguire5@gmail.com> - 2026-08-11 16:42 -0500
    Re: why is there not a ipow version of pow? Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2026-08-11 19:15 +0200
      Re: why is there not a ipow version of pow? Lynn McGuire <lynnmcguire5@gmail.com> - 2026-08-11 16:41 -0500
        Re: why is there not a ipow version of pow? Lynn McGuire <lynnmcguire5@gmail.com> - 2026-08-11 16:49 -0500
          Re: why is there not a ipow version of pow? bart <bc@freeuk.com> - 2026-08-11 23:28 +0100
            Re: why is there not a ipow version of pow? Lynn McGuire <lynnmcguire5@gmail.com> - 2026-08-11 17:51 -0500
        Re: why is there not a ipow version of pow? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2026-08-11 15:33 -0700
          Re: why is there not a ipow version of pow? Lynn McGuire <lynnmcguire5@gmail.com> - 2026-08-11 17:49 -0500
            Re: why is there not a ipow version of pow? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2026-08-11 16:19 -0700
              Re: why is there not a ipow version of pow? Lynn McGuire <lynnmcguire5@gmail.com> - 2026-08-12 00:32 -0500
                Re: why is there not a ipow version of pow? Bonita Montero <Bonita.Montero@gmail.com> - 2026-08-12 14:08 +0200
                  Re: why is there not a ipow version of pow? Bonita Montero <Bonita.Montero@gmail.com> - 2026-08-12 18:40 +0200
                    Re: why is there not a ipow version of pow? Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-08-14 02:50 +0000
    Re: why is there not a ipow version of pow? Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-08-12 04:26 +0000
      Re: why is there not a ipow version of pow? Lynn McGuire <lynnmcguire5@gmail.com> - 2026-08-12 01:37 -0500
        Re: why is there not a ipow version of pow? Paul <nospam@needed.invalid> - 2026-08-13 00:12 -0400
        Re: why is there not a ipow version of pow? Johann 'Myrkraverk' Oskarsson <johann@myrkraverk.invalid> - 2026-08-14 11:22 +0800
          Re: why is there not a ipow version of pow? Lynn McGuire <lynnmcguire5@gmail.com> - 2026-08-14 01:00 -0500
            Re: why is there not a ipow version of pow? Johann 'Myrkraverk' Oskarsson <johann@myrkraverk.invalid> - 2026-08-14 14:47 +0800
              Re: why is there not a ipow version of pow? Lynn McGuire <lynnmcguire5@gmail.com> - 2026-08-14 13:54 -0500
                Re: why is there not a ipow version of pow? Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-08-16 22:49 +0000
                  Re: why is there not a ipow version of pow? Lynn McGuire <lynnmcguire5@gmail.com> - 2026-08-17 14:56 -0500
                    Re: why is there not a ipow version of pow? Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-08-17 23:53 +0000
                      Re: why is there not a ipow version of pow? Lynn McGuire <lynnmcguire5@gmail.com> - 2026-08-17 19:59 -0500
                        Re: why is there not a ipow version of pow? Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-08-18 02:47 +0000
                  Re: why is there not a ipow version of pow? Lynn McGuire <lynnmcguire5@gmail.com> - 2026-08-17 15:17 -0500
              Re: why is there not a ipow version of pow? "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2026-08-14 12:03 -0700
                Re: why is there not a ipow version of pow? Johann 'Myrkraverk' Oskarsson <johann@myrkraverk.invalid> - 2026-08-15 03:51 +0800
                  Re: why is there not a ipow version of pow? "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2026-08-14 12:52 -0700
                    Re: why is there not a ipow version of pow? Johann 'Myrkraverk' Oskarsson <johann@myrkraverk.invalid> - 2026-08-15 04:01 +0800
                      Re: why is there not a ipow version of pow? "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2026-08-14 13:27 -0700
                        Re: why is there not a ipow version of pow? "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2026-08-14 13:29 -0700
                          Re: why is there not a ipow version of pow? Johann 'Myrkraverk' Oskarsson <johann@myrkraverk.invalid> - 2026-08-15 04:49 +0800
                            Re: why is there not a ipow version of pow? "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2026-08-14 20:32 -0700
      Re: why is there not a ipow version of pow? bart <bc@freeuk.com> - 2026-08-12 11:28 +0100
        Re: why is there not a ipow version of pow? Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-08-12 23:52 +0000
    Re: why is there not a ipow version of pow? Johann 'Myrkraverk' Oskarsson <johann@myrkraverk.invalid> - 2026-08-13 17:19 +0800
      Re: why is there not a ipow version of pow? Lynn McGuire <lynnmcguire5@gmail.com> - 2026-08-13 19:07 -0500
        Re: why is there not a ipow version of pow? Johann 'Myrkraverk' Oskarsson <johann@myrkraverk.invalid> - 2026-08-14 10:58 +0800
          Re: why is there not a ipow version of pow? Lynn McGuire <lynnmcguire5@gmail.com> - 2026-08-14 01:14 -0500
        Re: why is there not a ipow version of pow? Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-08-17 06:40 +0000
          Re: why is there not a ipow version of pow? Johann 'Myrkraverk' Oskarsson <johann@myrkraverk.invalid> - 2026-08-17 21:40 +0800
    Re: why is there not a ipow version of pow? Lynn McGuire <lynnmcguire5@gmail.com> - 2026-08-18 00:42 -0500
      Re: why is there not a ipow version of pow? Bonita Montero <Bonita.Montero@gmail.com> - 2026-08-18 09:34 +0200
      Re: why is there not a ipow version of pow? David Brown <david.brown@hesbynett.no> - 2026-08-18 11:32 +0200

Page 3 of 7 — ← Prev page 1 2 [3] 4 5 6 7  Next page →


#124734

From"Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>
Date2026-08-16 14:58 -0700
Message-ID<115tbpj$h6t7$1@dont-email.me>
In reply to#124724
On 8/14/2026 2:40 PM, Lynn McGuire wrote:
[...]

Fwiw, check this out, another one of my field renders:

https://youtu.be/ygmp_XvdaqQ

[toc] | [prev] | [next] | [standalone]


#124711

FromDavid Brown <david.brown@hesbynett.no>
Date2026-08-14 08:57 +0200
Message-ID<115me88$28idv$1@dont-email.me>
In reply to#124701
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.  For me, 200 points is 
>>> the point where diminishing returns has set in.  Of course, YMMV.
>>>
>>
>> Your mileage may very much vary.  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.  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.  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.  (I am using 
"interpolation" in a general sense here, including any kind of 
polynomial approximation - not specifically simple linear 
interpolation.)  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.

[toc] | [prev] | [next] | [standalone]


#124715

From"Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>
Date2026-08-14 12:46 -0700
Message-ID<115nraf$2qa1t$1@dont-email.me>
In reply to#124711
On 8/13/2026 11:57 PM, David Brown wrote:
> 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.  For me, 200 points 
>>>> is the point where diminishing returns has set in.  Of course, YMMV.
>>>>
>>>
>>> Your mileage may very much vary.  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.  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.  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.  (I am using 
> "interpolation" in a general sense here, including any kind of 
> polynomial approximation - not specifically simple linear 
> interpolation.)  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.
> 

Here is a fairly interesting interpolation... Fwiw, here is my driver 
code. I learned about this algo on a BASIC group. too funny! I ported it 
over to my system. It generates some frames for an animation:

#pragma once


#include "ct_multi_thread_field_final.hpp"
#include "ct_cairo.hpp"
#include "ct_complex.hpp"
#include "ct_geometry.hpp"
#include "ct_glm.hpp"

#include <iostream>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <string>


namespace ct {

     namespace swimmer {


         struct settings
         {
             float radius = 1;
             float t = 0;
             int n_points = 3000;
             float lw = 1;
             float sin_mul0 = 450;
             float sin_mul1 = 930;
         };

         void
         draw(
             ct::plot::cairo::plot_2d& plot,
             settings const& cfg
         ) {
             glm::vec2 prev(0.0f, 0.0f);

             for (int i = 0; i < cfg.n_points; ++i)
             {
                 float a = (float)i / (cfg.n_points - 1);

                 float at = 2 * a * CT_PI - 8 * cfg.t;
                 float b = glm::sin(cfg.sin_mul0 * a) * (0.7f + 
glm::sin(cfg.sin_mul1 * a));

                 float e = 2 * a * glm::exp(-a * 8);
                 float l = 1.5f * (0.7f - a) * (1 - b * b / 8) + cfg.t;
                 float w = e * b - glm::sin(at) / 12 + 0.75f;

                 glm::vec2 p(w * glm::cos(l), w * glm::sin(l));
                 p *= cfg.radius;

                 if (i > 0)
                 {
                     int col = (int)(128 + 127 * glm::cos(4 * b - a * 6));
                     unsigned char red = (unsigned char)glm::clamp(col, 
0, 255);
                     unsigned char blue = (unsigned char)glm::clamp(255 
- col, 0, 255);

                     ct::plot::cairo::pixel color = CT_RGB(red, 255, blue);
                     plot.line(prev, p, color, cfg.lw);
                 }

                 prev = p;
             }
         }


         void
         draw_pinwheel(
             ct::plot::cairo::plot_2d& plot,
             float t,
             unsigned long n = 10
         ) {
             float normal_base = 1.f / (n - 1);

             for (unsigned long i = 0; i < n; ++i)
             {
                 float normal = normal_base * i;

                 float r = normal;
                 float local_t = normal * n * 10 + t;   // outer t 
offsets the whole formation

                 draw(plot, { .radius = r, .t = local_t, .lw = 2 });
             }
         }


         void
         manifest_anime(
             ct::plot::cairo::plot_2d& scene,
             unsigned long fps,
             unsigned long duration
         ) {
             unsigned long frames = fps * duration;

             float normal_base = 1.f / frames;

             for (unsigned long i = 0; i < frames; ++i)
             {
                 float normal = normal_base * i;
                 float t = CT_PI2 * normal;

                 scene.clear(CT_RGBF(0, 0, 0));

                 draw_pinwheel(scene, t, 16);

                 {
                     std::string filename = 
"./ct_swimmer/frames/ct_frame_" + std::to_string(i) + ".png";

                     std::cout << "filename = " << filename << "\n";
                     std::cout << "normal = " << normal << "\n";
                     std::cout << "t = " << t << std::endl;

                     scene.save(filename.c_str());
                 }
             }
         }

         void
         manifest(
             ct::plot::cairo::plot_2d& scene
         ) {
             std::cout << "ct::swimmer()\n";
             std::cout << "__________________________________\n" << 
std::endl;

             {
                 manifest_anime(scene, 24, 5);
             }

             {
                // draw_pinwheel(scene, 0.0f);
                // draw_pinwheel(scene, 0.5f);
                // draw_pinwheel(scene, 0.75f);
                // draw_pinwheel(scene, 1.f);
                // draw_pinwheel(scene, 2.f);
                 //draw_pinwheel(scene, 3.f);


             }
         }
     }

} // ct::swimmer


[toc] | [prev] | [next] | [standalone]


#124698

FromJames Kuyper <jameskuyper@alumni.caltech.edu>
Date2026-08-13 12:59 -0400
Message-ID<115kt69$1qhgq$1@dont-email.me>
In reply to#124688
On 2026-08-12 16:44, Keith Thompson 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).

I would expect log2(x) to be easier to calculate than other bases when
using binary floating point, because the integer part of the result is
already stored (with an offset) as the exponent of the number; then you
can just calculate the fractional part from the significand. Similarly,
exp2(x) can just extract the integer part of x, and place it with the
correct offset in the exponent, and then calculate the significand of
the result from the fractional part. I don't know how significant a
savings that is, but it does seem like it should help. It might be
sufficiently significant to justify implementing exp(x) as
exp2(log(2)*x), and log(x) = log2(x)/log(2), where log(2) would be a
precomputed constant.

[toc] | [prev] | [next] | [standalone]


#124687

Fromantispam@fricas.org (Waldek Hebisch)
Date2026-08-12 20:23 +0000
Message-ID<115iknj$336tv$1@paganini.bofh.team>
In reply to#124671
In comp.lang.c David Brown <david.brown@hesbynett.no> wrote:
> 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:
>>>>
>>>>> He has numbers for dozens of x86 processors.  There are many others
>>>>> that he has not covered.  (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))".
>> 
>> 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).
> 
>> 
>>> /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".
> No, "log" and "exp" as words alone do /not/ imply base "e" - or any 
> 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.

I see.  It is kinda "obvious", but wrong.  In a sense base is a
trivial detail, you multiply result of 'log' by appropriate
constant to get any base you need and you divide argument of
'exp' to get different base.  But when you get to meat of the
calculation other bases have no advantage compared to base e
(for some approaches base e is a clear winner, for other it is
a tie).

> 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.
> 
> 
> 
> 

-- 
                              Waldek Hebisch

[toc] | [prev] | [next] | [standalone]


#124644

Fromscott@slp53.sl.home (Scott Lurndal)
Date2026-08-11 18:19 +0000
Message-ID<YIJeS.10822$EDc8.5203@fx24.iad>
In reply to#124627
Bonita Montero <Bonita.Montero@gmail.com> writes:
>Am 11.08.2026 um 17:11 schrieb David Brown:
>
>> He has numbers for dozens of x86 processors.  There are many others that 
>> he has not covered.  (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's what David stated, yes. 

That doesn't include PowerPC, uMIPS, ARMv7/8/9, S390, or the myriad
of small microcontrollers and utility processors still in common use.

[toc] | [prev] | [next] | [standalone]


#124645

FromBonita Montero <Bonita.Montero@gmail.com>
Date2026-08-11 20:21 +0200
Message-ID<115fp7m$7itg$1@raubtier-asyl.eternal-september.org>
In reply to#124644
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 ?

[toc] | [prev] | [next] | [standalone]


#124651

Fromscott@slp53.sl.home (Scott Lurndal)
Date2026-08-11 21:10 +0000
Message-ID<3dMeS.10826$EDc8.7526@fx24.iad>
In reply to#124645
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.

[toc] | [prev] | [next] | [standalone]


#124653

FromMichael S <already5chosen@yahoo.com>
Date2026-08-12 00:42 +0300
Message-ID<20260812004238.0000389b@yahoo.com>
In reply to#124651
On Tue, 11 Aug 2026 21:10:23 GMT
scott@slp53.sl.home (Scott Lurndal) wrote:

> 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.

Actually, it does not depend on clock speed alone.
More like on relationships betwween clock speed and power consumption.

Arm Cortex X4 reaches much higher clock speed than Neoverse-N2, but
it also consumes more power. At the end, latency of integer multiplier
is the same as N2 - 2 for regular multiply, 3 for umulh.

Even X925 that goes to quite extreme clock frequencies (and throughput),
has most of the latencies the same as N2. Only integer
multiple-accumulate is higher by 1 clock.

[toc] | [prev] | [next] | [standalone]


#124664

FromBonita Montero <Bonita.Montero@gmail.com>
Date2026-08-12 06:41 +0200
Message-ID<115gth3$hnni$1@raubtier-asyl.eternal-september.org>
In reply to#124651
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.

[toc] | [prev] | [next] | [standalone]


#124679

Fromscott@slp53.sl.home (Scott Lurndal)
Date2026-08-12 14:19 +0000
Message-ID<_h%eS.20009$YHa3.16532@fx15.iad>
In reply to#124664
Bonita Montero <Bonita.Montero@gmail.com> writes:
>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.

Yet another case where the AI is wrong.

[toc] | [prev] | [next] | [standalone]


#124680

FromBonita Montero <Bonita.Montero@gmail.com>
Date2026-08-12 16:56 +0200
Message-ID<115i1j4$t8ct$1@raubtier-asyl.eternal-september.org>
In reply to#124679
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.

[toc] | [prev] | [next] | [standalone]


#124681

Fromscott@slp53.sl.home (Scott Lurndal)
Date2026-08-12 15:32 +0000
Message-ID<Fm0fS.8308$AH8e.800@fx48.iad>
In reply to#124680
Bonita Montero <Bonita.Montero@gmail.com> writes:
>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.

https://support.arm.com/documentation/109914/0500/

page 21

[toc] | [prev] | [next] | [standalone]


#124684

FromMichael S <already5chosen@yahoo.com>
Date2026-08-12 22:05 +0300
Message-ID<20260812220517.00005423@yahoo.com>
In reply to#124664
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).

[toc] | [prev] | [next] | [standalone]


#124691

FromPaul <nospam@needed.invalid>
Date2026-08-12 19:09 -0400
Message-ID<115iuf5$16vgb$1@dont-email.me>
In reply to#124684
On Wed, 8/12/2026 3:05 PM, Michael S wrote:
> 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's how you ask the question, that matters :-)

For example, the level of detail in your paragraph, the machine
will suck that up like a sponge.

*********** Question ***************

Since I do not know the field well, I am going to give you
a word jumble, and you can construct an answer from the terms of it.

   CPU instructions:  umulh   umul   imul
                      Neoverse-N2 Cortex-A710 ARMv9 (A78)
                      Neoverse-N1 Cortex-A76

Write a cogent summary of the cycle count performance
for these items, as best you can.

***********   Answer  ***************  boom!

That killed the machine!!! Hahaha. Oh well, I
hope I get my quarter back. I'll have to run
this locally, and see if it blows that one up as well.
The online screen is jammed and it won't scroll. It's dead Jim.

Summary: Yes, it does matter how you ask the question.
         Another one for my book of trivia. FFS.

OK, ran the question locally, and this is the first part of the answer.
Took about 11 minutes locally, as I have no acceleration to speak of for it.

**Quick‑look table**

| Core (micro-arch)                        | Instruction*             | Operand size | Latency (cycles)   | Thruput (ops / cycle)  |
|------------------------------------------|--------------------------|--------------|--------------------|------------------------|
| **Neoverse-N1** – Cortex-A76 (ARMv8.2)   |  imul   (signed MUL)     | 32-bit       |         3          |           1            |
|                                          |                          | 64-bit       |        4-5         |           1            |
|                                          |  umul (unsigned MUL)     | 32-bit       |         3          |           1            |
|                                          |                          | 64-bit       |        4-5         |           1            |
|                                          |  umulh (unsigned UMULH   |
|                                          |         - high half)     | 32-bit       |         4          |           1            |
|                                          |                          | 64-bit       |        5-6         |           1            |
| **Neoverse-N2** - Cortex-A710            |  imul   (signed *MUL*)   | 32-bit       |         2          |           1            |
|                   (ARMv9 /"A78" family)  |                          | 64-bit       |         3          |           1            |
|                                          |  umul (unsigned *MUL*)   | 32-bit       |         2          |           1            |
|                                          |                          | 64-bit       |         3          |           1            |
|                                          | umulh (unsigned *UMULH*) | 32-bit       |         3          |           1            |
|                                          |                          | 64-bit       |         4          |           1            |

The high reasoning window was showing it wasn't entirely comfortable
with the labeling of the input in the question. But it does that
for other questions, so I won't treat that as any sort of evidence
of something. At least the machine did not roll over and die,
like the online one :-) In high-reasoning mode it can come back
quickly if it doesn't find any puzzles for itself. If the signal is
strong, maybe two runs and it is done with the reasoning.

The system monitor, shows it writes the blather in the high reasoning
window to disk. Now, I have to figure out where it is writing that.

If it found a "hole" in the dataset while in high
reasoning mode, it will grumble in its own special way about
the problem. And that was not evident. Didn't grumble. So
some sort of info is in the training set. My local model is
from a year ago Aug 2025 or so.

It never says "I don't know". It was claimed in some article, it
could do that. I don't think it can. The closest we got to an admission
of something was "I would be guessing if I answered that part".
Which means the info was detected as being missing from the training set.
In low-reasoning mode, it had been perfectly willing to "hallucinate"
some details (the answer changed on each run -- nice). Which is why the
run got repeated in the other mode, just to see what it would say.

   Paul

[toc] | [prev] | [next] | [standalone]


#124647

FromMichael S <already5chosen@yahoo.com>
Date2026-08-11 21:58 +0300
Message-ID<20260811215837.00001814@yahoo.com>
In reply to#124627
On Tue, 11 Aug 2026 17:20:14 +0200
Bonita Montero <Bonita.Montero@gmail.com> wrote:

> Am 11.08.2026 um 17:11 schrieb David Brown:
> 
> > He has numbers for dozens of x86 processors.  There are many others
> > that he has not covered.  (But he has done a truly amazing job with
> > the x86 world.)  
> 
> Agner covers almost all x86-microarcitecures that have been seen so
> far.
> 
> 

Last Intel's microarcitecure covered by Agner Fog is Sunny Cove,
featured in Ice Lake, Rocket Lake and Tiger Lake CPUs. (2019-2021).
He provides no information for anything more modern.
The claimed reasons is that all post-Tiger Intel laptop and desktop CPUs
use hybrid approach, containing mix of "perfformance" (* Cove) and
"efficiency" (* Mont) cores, so which makes measurements somewhat less
simple.
I would think that the real reason is his age, fatigue and being
now retired it's less easy for him to get access to different hardware
then when he was still in academy.

> > "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.
> 

So, 2.0**(b * log2(a)). Same shite, as long as you're not nitpicking.
 

[toc] | [prev] | [next] | [standalone]


#124666

FromRoss Finlayson <ross.a.finlayson@gmail.com>
Date2026-08-11 21:44 -0700
Message-ID<-eWcnfgBUfujZ-b3nZ2dnZfqnPidnZ2d@giganews.com>
In reply to#124620
On 08/11/2026 07:18 AM, Bonita Montero wrote:
> 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.
>

https://en.wikipedia.org/wiki/Stirling%27s_formula

If there's a neat way to compute factorial fast,
then there's a term in Stirling's formula that
gives e^n, that can be transformed to b^n.

Lanczos also has an approximation for n!,
also I wrote one in about 2003.


That Wikipedia is a fantastic resource and
all the bot-chat quite slurped and leeched it,
the bot-chat owes Wikipedia more than a gratuity.

[toc] | [prev] | [next] | [standalone]


#124622

Frombart <bc@freeuk.com>
Date2026-08-11 15:45 +0100
Message-ID<115fchf$2e17$1@dont-email.me>
In reply to#124619
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.  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:

  long long int ipow(long long a, int n) {
     long long int res;

     res = 1;
     if (n < 0) {
         res = 0;

     } else if (n == 0) {
         res = 1;

     } else if (n == 1) {
         res = a;

     } else if ((n & 1) == 0) {        // n is even
         res = ipow(a*a, n/2);

     } else {                          // n is odd
         res = ipow(a*a, (n-1)/2)*a;
     }

     return res;
  }

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.

>> 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.  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.  But it has no bearing to the OP and an integer 
> power function.

Maybe BM thinks that x**n requires n-1 multiplications.

[toc] | [prev] | [next] | [standalone]


#124624

FromBonita Montero <Bonita.Montero@gmail.com>
Date2026-08-11 16:56 +0200
Message-ID<115fd62$3263$2@raubtier-asyl.eternal-september.org>
In reply to#124622
This is the integer pow() code so far I wrote in C++:

template<typename Int>
constexpr optional<Int> ipow( Int b, Int e )
{
	constexpr bool Sgn = is_signed_v<Int>;
	using uint = make_unsigned_t<Int>;
	if( !b )
		return !e;
	uint ub, ue;
	if constexpr( Sgn )
		if( e >= 0 )
		{
			ub = abs( b );
			ue = abs( e );
		}
		else
			return abs( b ) == 1;
	else
		ub = b, ue = e;
	uint result = 1, msk = 1, sq = ub;
	while( ue )
	{
		if( (ue & msk) )
		{
			uint next = result * sq;
			if( next / sq != result )
				return nullopt;
			result = next;
			ue &= ~msk;
		}
		msk <<= 1;
		if( sq * sq / sq != sq )
			return nullopt;
		sq *= sq;
	}
	if constexpr( Sgn )
		if( bool neg = b < 0; neg && (e & 1) )
			if( result <= (uint)numeric_limits<Int>::min() )
				result = -(Int)result;
			else
				return nullopt;
	return result;
	
}

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.

[toc] | [prev] | [next] | [standalone]


#124628

FromDavid Brown <david.brown@hesbynett.no>
Date2026-08-11 17:23 +0200
Message-ID<115fep3$1659$7@dont-email.me>
In reply to#124624
On 11/08/2026 16:56, Bonita Montero wrote:
> 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.
> 

If you are writing a real integer power function with speed in mind, 
don't do that.  Use ckd_mul, or compiler-specific builtins (with 
appropriate compiler-specific conditional compilation).

[toc] | [prev] | [next] | [standalone]


Page 3 of 7 — ← Prev page 1 2 [3] 4 5 6 7  Next page →

Back to top | Article view | comp.lang.c++


csiph-web