Java: what is 1d?
Moved to the next expression in Java and I have no idea what "1d" ( r
is an integer) means . There are also options for lengths, doubles ... What are they for and what are they used for?
double y = r / (Integer.MAX_VALUE + 1d);
Thank!
The suffix d
after the number means double
, the suffix f
means the number with float
.
You can express a double literal eight ways: 1.0
, 1d
, 1D
, 1.0d
, 1.0D
, 1.
, 1.d
, 1.D
and not quite double literal: (double)1
. The last example 1
is a literal, int
but then I will cast it to double
.
In your expression: double y = r/(Integer.MAX_VALUE + 1d);
The parentheses increase the precedence of the expression, so (Integer.MAX_VALUE + 1d)
will be evaluated first, and since this the intValue + doubleValue
result will be of type double
so r/(Integer.MAX_VALUE + 1d)
will also double
.