How to use Power on D

Infiltrator Infiltrator at d.irc
Wed Jun 12 17:27:18 PDT 2013


On Thursday, 13 June 2013 at 00:24:18 UTC, Carlos wrote:
> So I have this code I'm working on but I get weird results. 
> What am I doing wrong ?
>
> Code :
>
> import std.stdio;
> import std.c.stdlib;
>
> void main()
> {
> foreach (count; 1 .. 16){
> 	write("Result : ", (2)^(count), " from : ", count, "\n");
> 	}
> }
>
> Prints:
>
> Result : 3 from : 1
> Result : 0 from : 2
> Result : 1 from : 3
> Result : 6 from : 4
> Result : 7 from : 5
> Result : 4 from : 6
> Result : 5 from : 7
> Result : 10 from : 8
> Result : 11 from : 9
> Result : 8 from : 10
> Result : 9 from : 11
> Result : 14 from : 12
> Result : 15 from : 13
> Result : 12 from : 14
> Result : 13 from : 15
>
> Thank you for your time.


I don't see the problem.  You're XORing 2 with 1..16 and getting 
the correct results.

Unless you actually want std.math.pow 
[http://dlang.org/phobos/std_math.html#.pow]?


More information about the Digitalmars-d-learn mailing list