[SOLVED] Double becomes infinity

Greetings,

I don’t know what to do to solve this. If anyone know what’s the problem, tell it to me in words. I am not learning if someone is pasting codes ^w^!
Tick

for (int i = 0; i < entities.size(); i++){
			if(entities.get(i) != sun){
				for (int j = 0; j < entities.size(); j++){
			        if (i != j){
			        	double dist = Math.sqrt(Math.exp(entities.get(i).getX() - entities.get(j).getX()) + Math.exp(entities.get(i).getY() - entities.get(j).getY()));
				        double accMag = entities.get(j).getMass()/(Math.exp(dist));
				        double accX = accMag*(entities.get(j).getX() - entities.get(j).getY())/dist;
				        double accY = accMag*(entities.get(j).getY() - entities.get(j).getY())/dist;
				        entities.get(i).addVX(accX);
				        entities.get(i).addVY(accY);
				        System.out.println("dist: " + dist + ", accMag: " + accMag + ", accX: " + accX + ", accY: " + accY);
			        }
				}
		        entities.get(i).updatePosition();	
		        System.out.println("New postition of Planet [x=" + entities.get(i).getX() + ", y=" + entities.get(i).getY() + "]");
			}
		}

System.out.println()

dist: Infinity, accMag: 0.0, accX: 0.0, accY: 0.0
New postition of Kerbin [x=80000.0, y=0.0]

Well the problem is basically as you can see, that dist is becomming Infinity, and because of this, the other variables are 0

-RoseSlayer

I’m not sure about Java, but with other languages (like lua), if the number gets too big, it will become infinity…

But I don’t really know why that is happening in your code… It most likely has to do with Math.exp because Math.sqrt would definitely make it smaller…

my guess is dist is actually zero and its squar-root is infinity.

what’s the exp of zero ?

Step backward: Math.exp(x) = e^x. you want x*x.

exp of zero is one.

yes, I want x^2. stupid of me …

[icode]System.out.println(Math.exp(80000));[/icode]

[quote]Infinity
[/quote]
There’s your problem. e80000