# [rrd-users] Re: Correct implementation of IF

Owen DeLong owen at delong.sj.ca.us
Wed Jul 25 21:26:10 MEST 2001

```Alex van den Bogaerdt wrote:
>
> Owen DeLong wrote:
>
> > > I doubt that "IF" will do the right thing here.  The source for
> > > 1.1.x doesn't seem to check for unknowns and even worse, it seems
> > > to handle them as "true".  Better make sure and use then "UN"
> > > statement here.
> > >
> > He's right again. :-(
>
> When in doubt, read the source :)
>
> Anyway, I think that the IF function should only return the first
> value if the condition is a finite value and if the condition != false.
> So, both infinite and unknown values should be equivalent to false.
>
> We have:  condition,a,b,IF and this works correctly for conditions
> that are finite numbers.  Please review the table below and discuss
> what would be the correct implementation.
>
> condition | return value
> ----------+-------------
> -infinite | -infinite or unknown or a or b ?
> +infinite | +infinite or unknown or a or b ?
>  unknown  |              unknown or a or b ?
>  <0       | return a
> ==0       | return b
>  >0       | return a
>

My vote would be as follows:

condition | return value | reasoning
----------+--------------+--------------------------------
-infinite | a            | -infinite is definitely not 0
+infinite | a            | +infinite is definitely not 0
unknown  | b            | Most languages treat undefined as 0
|              | in cases where a finite value must be
|              | substituted.
<0       | return a     | Any finite value not 0 should be true
==0       | return b     | 0 should be false
>0       | return a     | Any finite value not 0 should be true

The first three are potentially controversial.  The last three, I
believe,
are well accepted.  I know that PERL and C tend to operate along the
lines
of what I have outlined above.  Neither language directly supports
infinity, but in cases where infinity is required, usually they use
the largest possible (or smallest possible for -infinity) value.
In PERL, if undef is evaluated in a numeric context, it is treated as 0.
In C, there is no concept of undefined, but the convention of using NULL
as the value of an "undefined" pointer is widespread.  I have yet to see
a stdio.h in which NULL is not defined as 0.  In fact, I have yet to
encounter a programming language which allows you to evaluate undefined
as a finite value in a numeric context where the value is not treated
as 0 for numeric computation purposes.

As such, I believe the behavior I describe represents the most common
expectation of people using the tool.  Although this, alone, does not
justify using the particular method, absent significant benefit to doing
it in some other way, I think common expectation should prevail.

Owen

> cheers,
> --
>    __________________________________________________________________
>  / alex at slot.hollandcasino.nl                  alex at ergens.op.het.net \
> | work                                                         private |
> | My employer is capable of speaking therefore I speak only for myself |
> +----------------------------------------------------------------------+
> | Technical questions sent directly to me will be nuked. Use the list. |
> +----------------------------------------------------------------------+
> | http://faq.mrtg.org/                                                 |
> | http://rrdtool.eu.org  --> tutorial                                  |
> +----------------------------------------------------------------------+
>
> --
> Unsubscribe mailto:rrd-users-request at list.ee.ethz.ch?subject=unsubscribe
> Help        mailto:rrd-users-request at list.ee.ethz.ch?subject=help
> Archive     http://www.ee.ethz.ch/~slist/rrd-users

--
***********************************************************************
"Every time you turn on your new car, you're turning on 20
microprocessors.  Every time you use an ATM, you're using a computer.
Every time I use a settop box or game machine, I'm using a computer.
The only computer you don't know how to work is your Microsoft
computer, right?"
- Scott McNealy, CEO of Sun Microsystems, Inc.,
from an April 1997 interview in Upside Magazine

***********************************************************************
Microsoft CEO Bill Gates is optimistic about Contraceptive99's
potential.
He recently said, "Our contraceptive products will help users do to
each other what we've been doing to our customers for years."

The mail above is sent from my personal account and represents my own
views.  It may or may not reflect the opinions of Exodus Communications,
Jin Ho, Mo Sabourian, Tony Massing, Morris Taradalsky, or any other
employee, officer, subsidiary, acquisition, member, partner, aff

--
Unsubscribe mailto:rrd-users-request at list.ee.ethz.ch?subject=unsubscribe
Help        mailto:rrd-users-request at list.ee.ethz.ch?subject=help
Archive     http://www.ee.ethz.ch/~slist/rrd-users