Coder's Guild Mailing List

Re: Absolute values of phases

Posted by Sharvil Nanavati on 2000-11-21

> > > I'm creating a VB program that calculates numbers for phase.
> Since the
> > > program will return negative values as well as positive, I need
> to
> > > convert 
> > > negative numbers to positive numbers through basic code so that
> negative
> > > values will not appear.
> 
> > I cant say I know VB, but there will be a command such as 'ABS'
> which will
> > convert the given number to a positive number i.e. its absolute
> value.
> > Anothelengthy way could be to test if the number is less than 0,
> and if so
> > multiply it by -1.
> 
> I don't know what "phase" refers to either, and I don't know VB.
> 
> What kind of "numbers"?  (integers or reals)
> 
> I would recommend absolute value to avoid negative numbers, also.  If
> uniqueness is important, though, I would suggest an offset value
> (equal to
> the absolute value of the least negative number, e.g. 10 if valid
> values are
> -10..5).  Then add this offset before returning the value.  (The new
> range
> in example is 0..15.)  Perhaps that was a bad example if you want
> only
> positive numbers, but not if avoiding negatives...  isn't zero
> neither?
> 
> Well, anyway.  HTH

Why don't you just do this:

If x < 0 Then
    x = x * -1
End If

where x is your number. You could make a procedure out of this, and
you're all set. I don't know, maybe you wanted something more than just
multiplying by -1 when the number is negative. But this is what I would
end up doing...

Cheers,
Sharvil Nanavati

__________________________________________________
Do You Yahoo!?
Yahoo! Calendar - Get organized for the holidays!
http://calendar.yahoo.com/