Results 1 to 7 of 7

Thread: absolute value

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2000
    Location
    bebenia, PA, USA
    Posts
    241
    can someone enlighten me on absolute values?

  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177
    An Absolute Value is the Magnitude (Size) of a value, so the Absolute value of 1000 is 1000 and the Absolute value of -1000 is also 1000 .

  3. #3
    Hyperactive Member
    Join Date
    Jun 2000
    Location
    Auckland, NZ
    Posts
    411

    MAthermatical definition for you

    It can easily be expressed in VB code. I think you already know that the keyword "Abs" in VB does this right?

    Code:
    ' note that the value of "a" can be any real number
    ' you would decalre it like this:
    Dim a as Double
    
    ' and although the value of abs_a can only ever be positive,
    ' you still declare it as double because that's the closest
    ' than VB has..
    Dim abs_a as Double
    
    ' now for any value of a,
    ' where a>=0, the value of abs_a is equal to a
    ' and where the value of a is less than 0, then the value
    ' of abs_a is equal to 0 - a
    
    ' the IIf statement does this nicely
    abs_a = IIf(a >= 0, a, -a)
    
    ' otherwise the more elaborate cousing..
    If a >= 0 then
      abs_a = a
    Else
      abs_a = -a
    End If
    
    ' to code it with the least number of characters without using the Abs function (but relying on something that VB does with boolean expressions)
    abs_a = (a < 0) * a
    This ends the maths lesson

    Cheers

    P.S. I should have mentioned that another way of thinking of Absolute value is "the distance from 0" since distance is always "positive".


    [Edited by PaulLewis on 09-20-2000 at 10:45 PM]
    Paul Lewis

  4. #4
    Guest
    IAW, It it the POSITIVE VALUE of any number.

  5. #5
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    The absolute value of a imaginary value is sqr(real^2+imaginary^2) and the absolute value of a vector is he length of it, sqr(Vx^2+Vy^2)
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  6. #6
    Frenzied Member
    Join Date
    Aug 2000
    Location
    O!
    Posts
    1,177
    Ooops!

    Code:
    abs_a = (a < 0) * a
    returns the absolute value when a is negative, but it returns 0 when a is non-negative (a >= 0)

  7. #7
    Hyperactive Member
    Join Date
    Jun 2000
    Location
    Auckland, NZ
    Posts
    411

    oops

    returns the absolute value when a is negative, but it returns 0 when a is non-negative (a >= 0)
    Well that's pretty darn stupid of me. I should have known better than to try to be smart on the last line of a post! haha

    How many times have we all "added just one more line of code" before finishing for the day, only to come in the next morning and wonder, "What sort of idiot would have added that line of code? It won't compile now!"

    As a rule, I try not to code after lunch for that very reason. I find I'm even more slow-witted than normal after lunch..

    Thanks for spotting the error ccoder. I would like to say it was deliberate to see who was watching but ummm...wellll...

    Cheers
    Paul Lewis

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width