#Doubles vs integer values

1 messages · Page 1 of 1 (latest)

tranquil light
#

Programming motors on FTC Robot, does double effect anything or doesn’t matter?

double FORWARD_SPEED = 0.4

while (true){
frMotor.setPower(FORWARD_SPEED);
}

VS

while (true){
frMotor.setPower(0.4);
}

Right now motors tend to turn on faster than others. I’m new to Java compared to lua/python

silk gateBOT
#

Helper please have a look, thanks.

lean trench
#

0.4 is a "literal"

#

which i think you are confusing with "integer"

#

integers are 0, 1, 2, 3, ...

tranquil light
#

Oh, so doubling it doesn’t matter?

#

What would happen if I do float instead of double?

cedar inlet
#

does double effect anything or doesn’t matter?
its both a double value, regardless whether you explicitly specify it in a variable.
If this value a constant and always used in this place I would change it to
private static final double FORWARD_SPEED = 0.4
Otherwise it being initialized every time you create an instance of this class.
And if you question why I suggest this, you can read up on "magic numbers"

tranquil light
#

Okay

#

Thank you

lean trench
#

what do you mean by this?

#

double is kinda a strange name for floating point number, but its the one to use

lean trench
fading hearth
#

double is a double precision floating point number according to the IEEE 754 standard.
float is a single precision floating point number

tranquil light
#

Sorry I don’t know how to disable this thread

frosty loom
#

its automatic. or u use /help-thread close

covert rampart
warm tiger
covert rampart
#

well, at least they have a good use for nans