to use 3 registers: one to roll y, one to hold the squares of x,
and one to hold
the result.
Writing the same algoritm with assembler language can save a few instructions
per loop,
because gcc doesn't catch that it can use the out-going bit of y to directly
jump over xy *= x;
if not set. But it won't be portable then.
Best regards,
Nicolas Argyrou
I'm ok with using Bash's licence.
- Original Message -
From: William Park
To: Nicolas ARGYROU
Cc: bashbug
Sent: Monday, September 19, 2011 3:33 AM
Subject: Re: Bug fix for $((x**y)) algorithm on 64+ bits machines.
No. For example, current Bash is copyrighted and licen
)
Regards,
Nicolas Argyrou
- Original Message -
From: Dave Rutherford
To: Nicolas ARGYROU
Cc:
Sent: Saturday, September 17, 2011 10:34 PM
Subject: Re: Bug fix for $((x**y)) algorithm on 64+ bits machines.
On Sat, Sep 17, 2011 at 07:10, Nicolas ARGYROU wrote:
> I came up with a
I'm glad it pleases you. I'm amazed also how fast it deals with large numbers.
Feel free to use it. :)
I came up with a version that is slightly more precise in the comments, and
that uses 3 registers instead of 4
(though gcc can optimize that):
// Copyright 2011: Nicolas Argyro
unsigned integer type, and doesn't
need any external resource:
// Copyright 2011: Nicolas Argyrou , public domain.
template
inline T ipow(register T x, register T y)
{
if (x == 0 && y != 0) return 0;
// 1: ipow(x,y) = x ** y = Product [i=0; i>i)&1)*2**i))
// 2: x