Is there a simple way to change a positive number to a negative number???
float d = 1.0f; How can I flip d between pos. and neg.?
Thanks in advance
if (d > 0)
{
d = -(d);
}
else if (d < 0)
{
d = Math.abs(d);
}
Of course this would work for both:
d = -(d);
that would make positive values negative and negative values positive.
server_crash
Postaholic
2,111 posts since Jun 2004
Reputation Points: 113
Solved Threads: 20
change this
private float d = 2.0f, sum = 1.0f, term = 0.0f;
It's very bad practice to declare multiple variables on a single line, never do it!
jwenting
duckman
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
change this
private float d = 2.0f, sum = 1.0f, term = 0.0f;
It's very bad practice to declare multiple variables on a single line, never do it!
Actually you can't declare floats with decimall places can you? You have to add d a 'd' at the end to symbolize a double.
server_crash
Postaholic
2,111 posts since Jun 2004
Reputation Points: 113
Solved Threads: 20
no, you can. Unless you specify the f at the end it defaults to a double though (causing a compiler error).
float is a single precision floating point number, double a double precision floating point number.
jwenting
duckman
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
no, you can. Unless you specify the f at the end it defaults to a double though (causing a compiler error).
float is a single precision floating point number, double a double precision floating point number.
K, I knew I was going wrong somewhere.
server_crash
Postaholic
2,111 posts since Jun 2004
Reputation Points: 113
Solved Threads: 20