-
Book Overview & Buying
-
Table Of Contents
D Cookbook
By :
D has a built-in exponentiation operator: the ^^ operator.
In order to use the exponentiation operator, we need to execute the following steps:
Write an expression with the ^^ operator.
Make one or both arguments floating point if you want a floating point result.
The code is as follows:
int a = 2^^3; // a == 8 float b = 2.0 ^^ 3.0; // b == 8.0 auto c = 2 * 2 ^^ 3; // c == 16
The exponentiation operator is first subject to constant folding and is then rewritten into a call to the std.math.pow library function to perform the operation. The result follows the regular arithmetic type rules of the D language, so the int arguments yield an int result and the float arguments yield a float result.
The operator also follows the usual arithmetic order of operations, so it has higher precedence than multiplication, as seen in the third example line.
The choice of ^^ for the operator was driven by the desire: to look like ASCII math without being...
Change the font size
Change margin width
Change background colour