GMLscripts.com

Discuss and collaborate on GML scripts
Invert

You are not logged in.

#1 2015-09-11 04:37:55

GameGoblin
GameGoblin
From: India
Registered: 2015-06-30
Posts: 8
Website

sign_opposite()

Expand///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

#2 2015-09-12 15:15:16

xot
Administrator
Registered: 2007-08-18
Posts: 1,240

Re: sign_opposite()

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

#3 2016-01-08 06:29:20

AnastasiaDunbar
Member
Registered: 2015-12-22
Posts: 12

Re: sign_opposite()

What about this?

Expand///sign_opposite(val1,val2)
return sign(argument0) != sign(argument1);

Offline

#4 2016-01-10 06:32:35

xot
Administrator
Registered: 2007-08-18
Posts: 1,240

Re: sign_opposite()

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

#5 2016-01-10 11:55:42

AnastasiaDunbar
Member
Registered: 2015-12-22
Posts: 12

Re: sign_opposite()

But there isn't well opposite of zero? Is it infinite?

Offline

#6 2016-01-10 13:51:49

xot
Administrator
Registered: 2007-08-18
Posts: 1,240

Re: sign_opposite()

*shrug*

I don't understand the point of the script to be honest.


Abusing forum power since 1986.

Offline

#7 2017-05-31 19:50:17

JFitch
Member
Registered: 2017-05-31
Posts: 2

Re: sign_opposite()

Two numbers have the opposite sign if the product is negative.

Expandreturn ((argument0*argument1)<0)

Offline

#8 2017-06-06 12:13:20

xot
Administrator
Registered: 2007-08-18
Posts: 1,240

Re: sign_opposite()

We got there in the end and it only took nine months.


Abusing forum power since 1986.

Offline

Board footer

Powered by FluxBB