SA-MP Forums Archive
[Include] Unsigned numbers - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Filterscripts (https://sampforum.blast.hk/forumdisplay.php?fid=17)
+---- Forum: Includes (https://sampforum.blast.hk/forumdisplay.php?fid=83)
+---- Thread: [Include] Unsigned numbers (/showthread.php?tid=311413)



Unsigned numbers - Slice - 16.01.2012

Hey,

This is a simple include that provides support for unsigned multiplication, division, and modulo operations.
Similar to how float numbers work in PAWN, you just add the tag "unsigned" to the variable/number.

Brief example:
pawn Код:
#include <a_samp>
#include <unsigned>

main () {}
   
public OnGameModeInit() {
    new
        unsigned:test1,
        unsigned:test2
    ;
   
    test1 = 1;
    test2 = -1;
   
    if (test2 > test1)
        print("unsigned: -1 > 1"); // prints
   
    printf("%d",   test2 % 255); // 0
    printf("%d", _:test2 % 255); // 254
    printf("%d",          -1000 % 255); // 20
    printf("%d", unsigned:-1000 % 255); // 21
    printf("%d",          0xFFFFFF9C / 5); // -20
    printf("%d", unsigned:0xFFFFFF9C / 5); // 0x3333331F
    printf("%d",                 0xFFFFFFFF ); // -1
    printf("%s", unsigned_string(0xFFFFFFFF)); // 4294967295
}
Download: unsigned.inc


Re: Unsigned numbers - T0pAz - 16.01.2012

Looks good. Have to download this.


Re: Unsigned numbers - steki. - 16.01.2012

What the fuck. That's awesome!


Re: Unsigned numbers - SoUrAv - 16.01.2012

Gud job slice.


Re: Unsigned numbers - Hiddos - 16.01.2012

Do like, I'll definitely be using this!


Re: Unsigned numbers - Slice - 16.01.2012

Thanks, guys.

I updated the include with a new function: unsigned_string(value).
This function returns a string with an unsigned base 10 representation of the number.

Example:
pawn Код:
printf("%d",                 0xFFFFFFFF ); // -1
printf("%s", unsigned_string(0xFFFFFFFF)); // 4294967295
Edit: unsigned_string is now roughly 50 times faster than the previous version!