Archived

This topic is now archived and is closed to further replies.

logout

math operator ...

Recommended Posts

It means the absolute value of the value encapsulated between the |'s. That is, |V| == abs(V) where

float abs(float x){
if (x<0) return -x;
else return x;
}

In C/C++ code, | means bitwise or (|| = logical or).

Edit: woops... the next poster is right

[edited by - Kurioes on January 5, 2003 2:05:39 PM]

Share this post


Link to post
Share on other sites
Ok, I am a bit tired, so my mind might be messed up, but isn''t you abs() function a bit weird.
It could as well just say "return x;" since that is all it does...

Isn''t this the correct way:

  
float abs(float x)
{
if(x < 0)
return -x;
else
return x;
}


Simplier put, it is as this:
x = 10
|x| = 10

y = -5
|y| = 5

If the number is negative, then just remove the "-"-sign.
The absolute value is actually just the size of the number, not considering which direction it is facing (well, mostly we just delas with 1 dimension, and then you have negative and positive numbers, but if you count in 2 dimensions, then |x| would be the size of your 2d-value (actually, it is the length of a line...).

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
It also means the length of a vector, ie if you have a vector:

v(x, y, z)

then |v| =

sqrt( x^2 + y^2 + z^2 )

Which is defined as the absolute value operation on a vector, it''s just a bit more of a calculation than the above answer (which is correct) for a scalar number..

Share this post


Link to post
Share on other sites
quote:
Original post by Predictor
This is only true for real numbers.



Okay... I had assumed we WERE discussing reals (scalar and vector), as opposed to say complex numbers or matrices.

I would have assumed that the distinction was rather obvious and didn''t need further clarification!

Timkin

Share this post


Link to post
Share on other sites