Jump to content
  • Advertisement

Archived

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

logout

math operator ...

This topic is 5648 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

many times i have seen somthing incaplulated with ''|'' what does this meen ? *like : |A| * or * |V| * can anybody explain this ?

Share this post


Link to post
Share on other sites
Advertisement
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
Mathematically, |V| is equivalent to sqrt(V2).

Cheers,

Timkin

[edited by - Timkin on January 5, 2003 5:55:34 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by Timkin
Mathematically, |V| is equivalent to sqrt(V2).
[edited by - Timkin on January 5, 2003 5:55:34 PM]


This is only true for real numbers.



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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!