pow
H. S. Teoh
hsteoh at quickfur.ath.cx
Wed Mar 21 16:15:13 UTC 2018
On Wed, Mar 21, 2018 at 03:56:00PM +0000, aerto via Digitalmars-d wrote:
> why pow(256, 27) gives 0, instead of
> 105312291668557186697918027683670432318895095400549111254310977536L
Because 256, being an int type, can only hold a 32-bit result, the
maximum of which is 2^31 (or 2^32 if you use uint). But 256^27 = 2^216,
far bigger than a 32-bit int can hold.
As Adam said, you probably want to use BigInt instead:
import std.bigint;
auto result = pow(BigInt(256), 27);
T
--
Food and laptops don't mix.
More information about the Digitalmars-d
mailing list