Exact arithmetic with quadratic irrationals
Timon Gehr via Digitalmars-d
digitalmars-d at puremagic.com
Wed Apr 19 17:30:43 PDT 2017
On 20.04.2017 02:01, Timon Gehr wrote:
>
> My last post includes an implementation of this algorithm. ;)
But in that implementation I used the parameter 'a' instead of the
variable 'x' as a result of being tired, which makes it slightly more
confusing than necessary even though it is correct. More readable version:
auto pow(T,S)(T a,S n){
T r=T(ℕ(1),ℕ(0));
for(auto x=a;n;n>>=1,x*=x)
if(n&1) r*=x;
return r;
}
More information about the Digitalmars-d
mailing list