Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sign function

Status
Not open for further replies.

vivasuzi

Programmer
Jun 14, 2002
183
0
0
Does anyone know what you have to include in order to use the sign() function? I know it's a function b/c a teacher gave me code that uses it, he just forgot to tell us what to include. [hourglass] time is ticking, please tell me soon! Thanx :) *Suzanne*
 
In VC++ go under 'help->index' menu and type in 'sign' - find the relevant function and it'll tell you which headers are required.
I would do it for you but I don't have it on this particular PC I'm using right now.
tellis.gif

[sup]programmer (prog'ram'er), n A hot-headed, anorak wearing, pimple-faced computer geek.[/sup]​
 
I had a look and the only sign() functions I could find are for visual basic and visual fox pro. I'll have a look on the internet for you.
tellis.gif

[sup]programmer (prog'ram'er), n A hot-headed, anorak wearing, pimple-faced computer geek.[/sup]​
 
Hi ,
I'm having the same problem ...

functions like abs() work ...
only not sign() ??

this is my include :
#include <Math.h>

this is the implementation :
(*out2++) = (*in2++) * abs(Sign(fTreshold - *in2));

this is the error :
error C2065: 'Sign' : undeclared identifier

?? h e l p ??
 
Staccato, your problem is that you are using &quot;sign&quot; not &quot;sin&quot;.

Use sin().
 
PS- &quot;sine&quot; is a homonym of &quot;sign&quot;. Are you wanting to use the sine and cosine functions Suzi?
 
sin = sinus
sign = signus

signus returns -1 on a negative value ,
0 on a 0,
and 1 one a positive value

__

the documentation says it's a Math member , like sin
but I can use sin , not sign

??
 
For the life of me, I can't find the function you're looking for. All I can seem to determine is that it doesn't seem to be in math.h.
 
I see. I wonder if it's a .NET addition. Are you using VC++ 6?
 
const int sign( const int x )
{
if ( x > 0 )
return 1;
else if ( x < 0 )
return -1;
else return 0;
}

I suppose you could just use this in the meantime.
 
I remember trying to find this [tt]sign()[/tt] a while ago.

a more efficient way would be to:

[tt]bool sign(const int i)
{
return (i==abs(i));
}[/tt]
tellis.gif

[sup]programmer (prog'ram'er), n A hot-headed, anorak wearing, pimple-faced computer geek.[/sup]​
 
Stylish, but the function is supposed to have 3 return values for positive, negative, and zero.
 
serves me right for not reading the link!! :)

[tt]int sign(const int i)
{
return ((i==0)?0:(int)(i==abs(i))?1:-1);
}[/tt]
tellis.gif

[sup]programmer (prog'ram'er), n A hot-headed, anorak wearing, pimple-faced computer geek.[/sup]​
 
how the heck does this work? never seen code like this before?

return ((i==0)?0:(int)(i==abs(i))?1:-1);
 
(if true) ? do this : otherwise do that ;

actually, I misunderstood the whole sign() function thingy through my own laziness of reading the posts - armed with the knowledge of the three return values it should be:

[tt]return ((i==0)?0:(i>0)?1:-1);[/tt]
tellis.gif

[sup]programmer (prog'ram'er), n A hot-headed, anorak wearing, pimple-faced computer geek.[/sup]​
 
Kewl , thanx!!

the only problem is that it's a sound processing module , so normally it gets processed thru an algorithm.
I think this has the advantage of being much faster than a if/else structure

or am I wrong here ??

I formulated the signus function as follows :

x = x * ( 1 / abs( x ) )

and it seems to handle it correctly , although at a value 0 , isn't there an attempt to divide by zero ??
but maybe it's catched ??
 
> much faster than a if/else structure

no, multiplying/dividing is 100 times slower as if/else for integers and 1000 times for floats.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top