1. How to prevent division by zero?

I need to prevent division by zero. As I know, Euphoria's atoms used for integer and float numbers. Whether means it, what I should check both cases?

if x = 0 or x = 0.0 then
  y = INFINITE 
else 
  y = 1 / x 
end if

Perhaps, more correct to make so?

if x > -0.0000000001 and x < 0.0000000001 then

Please, don't suggest me to intercept an exception! I understand that it is the most ideologically certain way, but it is superfluous difficult for my modest utilities.

new topic     » topic index » view message » categorize

2. Re: How to prevent division by zero?

SnakeCharmer said...

I need to prevent division by zero.

This should be enough ...

include std/math.e 
if x = 0  
  y = PINF -- Positive infinity 
else 
  y = 1 / x 
end if 

[/quote]

new topic     » goto parent     » topic index » view message » categorize

3. Re: How to prevent division by zero?

Thanks!

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu