Page 1 of 1

Converting a negative value to a positive

Posted: Thu Apr 07, 2005 4:55 pm
by Hroudtwolf
Hallo Comunity,

Can anyone explain me , how to convert a negative value to a positive ?


Thanks for your answer ...

Posted: Thu Apr 07, 2005 4:56 pm
by El_Choni

Code: Select all

value = -value

Posted: Thu Apr 07, 2005 5:34 pm
by dracflamloc
That works in pb?

In general you will need to do something more like:

value=value*-1;

Which is what Choni's example does anyway, but this is non-specific to PB.

Posted: Thu Apr 07, 2005 5:38 pm
by Le Soldat Inconnu
Or use the ABS() function, see the help

Posted: Thu Apr 07, 2005 6:02 pm
by Hroudtwolf
thanks @ALL.

I got the answer already in PureBasic-Lounge.

Posted: Thu Apr 07, 2005 6:07 pm
by El_Choni
At least in x86 CPUs multiplying a value takes more time than negating it. In my mind, too :mrgreen:

Posted: Thu Apr 07, 2005 6:11 pm
by traumatic
dracflamloc wrote:That works in pb?

In general you will need to do something more like:

value=value*-1;

Which is what Choni's example does anyway, but this is non-specific to PB.
What do you mean?

Code: Select all

#include <stdio.h>

int main(int argc, char* argv[])
{
	long value = 12345;

	value *= -1;
	printf("value: %d\n", value);

	value =- value;
	printf("value: %d\n", value);

	value =~ value+1;
	printf("value: %d\n", value);

	return 0;
}

Posted: Thu Apr 07, 2005 11:10 pm
by Fred
"value = -value" is probably the fastest (and easiest) way to reverse sign in PB.

Posted: Fri Apr 08, 2005 7:19 am
by Falko
:wink:

Posted: Fri Apr 08, 2005 8:19 am
by Rings
i'm too lazy to answer


sorry only in german

Posted: Fri Apr 08, 2005 8:22 am
by leo1991
Rings wrote:i'm too lazy to answer


sorry only in german
:o :o :?:

Posted: Fri Apr 08, 2005 9:51 am
by dige
:lol: nice link Rings ...