You are not logged in.
Pages: 1
///sign_opposite(val1,val2)
//
//tells if two integers have opposite signs
//
//val1: the first value/variable to compare
//val2: the second value/variable to compare
return ((argument0 ^ argument1) < 0);
Offline
Sorry, that just doesn't work very well.
It doesn't work with floating-point values.
sign_opposite(-1, 0) returns true.
I know it says it only works with integers, but all numeric variables are internally represented by floating-point values. This seems like asking for trouble.
If it did work, it seems like it might be a susceptible to differences in architecture and precision errors.
EDIT:
Hmmm. Actually seems to work slightly better when floats are variables rather than with literals. Only in the case of non-negative values though. Weird.
Last edited by xot (2015-09-12 15:24:59)
Abusing forum power since 1986.
Offline
What about this?
///sign_opposite(val1,val2)
return sign(argument0) != sign(argument1);
Offline
That would tell you if the signs were different but not necessarily if they were opposite. Sign returns [-1, 0, 1].
Abusing forum power since 1986.
Offline
But there isn't well opposite of zero? Is it infinite?
Offline
*shrug*
I don't understand the point of the script to be honest.
Abusing forum power since 1986.
Offline
Two numbers have the opposite sign if the product is negative.
return ((argument0*argument1)<0)
Offline
We got there in the end and it only took nine months.
Abusing forum power since 1986.
Offline
Pages: 1