[Include] Unsigned numbers
#1

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
Reply
#2

Looks good. Have to download this.
Reply
#3

What the fuck. That's awesome!
Reply
#4

Gud job slice.
Reply
#5

Do like, I'll definitely be using this!
Reply
#6

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!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)