|
-
Sep 20th, 2000, 09:22 PM
#1
Thread Starter
Addicted Member
can someone enlighten me on absolute values?
-
Sep 20th, 2000, 09:36 PM
#2
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 .
-
Sep 20th, 2000, 09:42 PM
#3
Hyperactive Member
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]
-
Sep 21st, 2000, 12:02 AM
#4
IAW, It it the POSITIVE VALUE of any number.
-
Sep 21st, 2000, 03:43 AM
#5
transcendental analytic
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.
-
Sep 21st, 2000, 09:32 AM
#6
Frenzied Member
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)
-
Sep 21st, 2000, 02:19 PM
#7
Hyperactive Member
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|