BBC BASIC for Windows
General >> General Board >> Division by zero!
http://bb4w.conforums.com/index.cgi?board=general&action=display&num=1472330343

Division by zero!
Post by Ric on Aug 27th, 2016, 8:39pm

I have come across an annoying problem. When trying to calculate an angle using ATN I get a divide by zero error. I know that the error is correct because the second variable is zero, but surely the code should return 90degrees.

angle=ATN(var1/var2)

If var2=0 then the error occurs. I know that what is in the brackets is a division by zero, but how do I get round this problem?

Ric

Sorry, forgot to say
var1 is the opposite and
Var2 is the adjacent.

They are always changing.

P.S. I'd rather not solve it by error trapping or testing for zero.

Re: Division by zero!
Post by sbracken on Sep 7th, 2016, 12:53pm

Given the error is inevitable when var2 is zero, you are going to have to have some sort of error trapping or testing to catch it.

As always, Richard is one step ahead:

https://bb4w.wikispaces.com/The+ATAN2+function

Simon