# Thread: error: division by zero

1. ## error: division by zero

When this calculation is run, I get this:

Warning: Division by zero in sql5.php on line 79

line 79 is this one -

\$radDist = atan(-\$X / sqrt(-\$X * \$X+1)) + 2 * atan(1);

PHP Code:
```  \$latRad1 = \$lat1 * pi / 180; \$lonRad1 = \$lon1 * pi / 180; \$latRad2 = \$lat2 * pi / 180; \$lonRad2 = \$lon2 * pi / 180; \$lonRadDif = abs(\$lonRad1-\$lonRad2); \$X=sin(\$latRad1)*sin(\$latRad2)+cos(\$latRad1)*cos(\$latRad2)*cos(\$lonRadDif); \$radDist = atan(-\$X / sqrt(-\$X * \$X+1)) + 2 * atan(1); \$distCalc=\$radDist*3958.754;  ```
Can you help me make this work properly? If you need the whole code, let me know and I'll post it.

2. Well division by zero is obviously a mathematical problem. If you insist on trying to do that, or if it's a possibility and you don't WANT the errors to show up, just suppress it with an @.

That's probably not what you wanted to hear, but otherwise you need to ensure that you're not dividfing by 0... :\

Also, this looks like a longitude, latitude distance calculator. What happens when you feed London's Longitude value of 0 Deg, 0 Mins in? Won't this cause a divide by zero?

4. torrent,

All of those are set from a db table for the US.

I am working on posting a test page you can go to and see all the involved values and the calculations.

5. I'd just make sure that the value isn't 0 first before doing the calculation.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•