Posted by

mcvillarp on January 28, 2008 at 8:18 PM PST

I'm learning Java, and guessing that float arithmetic is faster than double arithmetic, I made a simple program: to sum 10,000,000 times 3

I found that double is faster than float ... but I forgot that when, with double I got 3.0E7, the correct result and with float I got 3.4407592E7 .... Â¿What is happening?

Testing, the problem starts at 5,592,409 ... very far from 3.4028235E38

I can't find my mistake ... please, help me to understand.

Code (I omitted the time instructions and logic trying to focus mi problem):

public class ErrorFloat {

public static void datoFloat(int limite){

float suma=0.0f;

for (int i=0;i