help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: help - warning division by zero


From: Joe Tusek
Subject: RE: help - warning division by zero
Date: Fri, 25 Oct 2019 06:12:18 +0000

Hi Andrew,

I hadn't even considered the possibility that it was not an Octave command. I 
just thought it was undocumented.

What is the easiest way to find out where it is coming from? 

I tried stepping into it but couldn't. 

Regards,
Joe

Joe Tusek (BE MBA)
Technical Director
23 Warabrook Boulevard, Warabrook, NSW 2304
P +61 2 4961 9000  M +61 418 669 250

-----Original Message-----
From: Andrew Janke <address@hidden> 
Sent: Friday, 25 October 2019 5:04 PM
To: Joe Tusek <address@hidden>; address@hidden
Subject: Re: help - warning division by zero



On 10/25/19 1:58 AM, Joe Tusek wrote:
> Hi,
> 
> 
> I have code that uses ifelse statements to prevent the possibility of 
> a division by zero. It appears though that all the conditions of the 
> ifelse are evaluated as part of the ifelse execution and this results 
> in a warning about a division by zero, even if the code should prevent 
> such a case.
> 
> This leaves a warning of division by zero in the Command Window when 
> the "executed code" had not resulted in one.
> 
> The code snippet has been crafted to generate the behaviour
> 
>>> ifelse (1==1,0,1/0)
> 
> warning: division by zero
> 
> ans = 0
> 
>>> ifelse (1==0,0,1/0)
> 
> warning: division by zero
> 
> ans =  Inf
> 
>>> ifelse (1==0,0,1)
> 
> ans =  1
> 
> Should this warning be supressed (so that it does not appear in the 
> Command Window) when there was no active code that resulted in a 
> division by zero?

Hi Joe,

What is this "ifelse" statement or function that you're using in your example 
code? Octave doesn't have an "ifelse" statement.

If this is a function you've implemented yourself, you need to know that Octave 
is an "eager-evaulation" language: all the input arguments to a function are 
*always* evaluated before being passed in. So that "1/0"
that is the 3rd argument to the function always happens. This isn't like a Lisp 
or whatever where you can have "lazy" evaluation.

To have something like this "short-circuit" and prevent argument evaluation 
requires special support at the language level.

Cheers,
Andrew



reply via email to

[Prev in Thread] Current Thread [Next in Thread]