Results 1 to 9 of 9

Thread: Long Int

  1. #1
    Private
    Join Date
    Oct 2014
    Posts
    32
    Thanks
    0
    Thanked 5 Times in 4 Posts

    Long Int

    Hey guys,

    I have a problem with big numbers inside gsc.
    I have a loong number in a string. I can extract it but datatype still seems to be a string, so I can't use it for calculations.

    I casted the string using (int) but the max value of a normal integer is exceeded.

    Is there a possibility to use a long int for example? Float seems to have same limitations as int..

    Thanks for answers!

  2. #2
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,718
    Thanks
    17
    Thanked 1,068 Times in 674 Posts
    Cod2 does not support anything above 32bit data types, so you have to store it either in raw memory, making calculations harder, or in a string, making calculations near impossible.

    What are you trying to achieve with it?
    "Does not work" is an error report for a bug between keyboard and chair.

    All hail Artie Effem

  3. #3
    Private
    Join Date
    Oct 2014
    Posts
    32
    Thanks
    0
    Thanked 5 Times in 4 Posts
    The number is the score of a player. The first player is no reaching the limits.. I have something to do :/
    How could I store it in raw memory?

    It's for UO anyway

  4. #4
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,718
    Thanks
    17
    Thanked 1,068 Times in 674 Posts
    How is a player ever reaching such a score of 2 BILLION?

    Given that you're generous and give 100 xp/kill, the player has to get 20 million kills. This means that, given 1 kill per second, he'd have to continuously keep killing people at said rate for over 5000 hour or over 200 days.

    If you're giving more than 100 xp/kill, i'd advise you to either lower that, or just add a multiplier to the score (kill = 1000xp, store xp in multiples of 1000)
    "Does not work" is an error report for a bug between keyboard and chair.

    All hail Artie Effem

  5. The Following User Says Thank You to IzNoGoD For This Useful Post:

    kung foo man (20th November 2015)

  6. #5
    Assadministrator kung foo man's Avatar
    Join Date
    Jun 2012
    Location
    trailerpark
    Posts
    2,011
    Thanks
    2,102
    Thanked 1,084 Times in 753 Posts
    Or, if you are masochistic, add a binding of a big number library to gsc:

    https://gmplib.org/

    Code:
    gcc -o add_example add_example.c -lgmp -lm
    Code:
    #include <stdio.h>			/* for printf */
    #include <gmp.h>
     
    int main(int argc, char *argv[])
    {
      mpz_t a, b;                 		/* working numbers */
      if (argc<3)
        {					/* not enough words */
        printf("Please supply two numbers to add.\n");
        return 1;
      }
      mpz_init_set_str (a, argv[1], 10);	/* Assume decimal integers */
      mpz_init_set_str (b, argv[2], 10);	/* Assume decimal integers */
      mpz_add (a, a, b);			/* a=a+b */
    
      printf("%s + %s => %s\n", argv[1], argv[2], mpz_get_str (NULL, 10, a));
      return 0;
    }
    timescale 0.01

  7. #6
    Private
    Join Date
    Oct 2014
    Posts
    32
    Thanks
    0
    Thanked 5 Times in 4 Posts
    How can I add a new data type to gsc then?

  8. #7
    Assadministrator kung foo man's Avatar
    Join Date
    Jun 2012
    Location
    trailerpark
    Posts
    2,011
    Thanks
    2,102
    Thanked 1,084 Times in 753 Posts
    Oh, you wanna add big int types to the scripting engine instead of a simple binding of a big int library?

    Then you just gotta reverse engineer and fit the bison/flex scanner/parser/opcode generator/interpreter.

    As easy introduction I suggest this little toy language: http://www.peroxide.dk/tuts_scr.shtml
    timescale 0.01

  9. #8
    Private
    Join Date
    Nov 2014
    Posts
    25
    Thanks
    9
    Thanked 3 Times in 2 Posts
    How you reach 2,147,483,647 I don't know but from memory a friend of mine bypassed the 32bit int limit by using strings and using B for Billion, T for Trillion etc.

  10. #9
    Private
    Join Date
    Oct 2014
    Posts
    32
    Thanks
    0
    Thanked 5 Times in 4 Posts
    I used strings now Was the easiest method. To calculate the strings I use a helper function in c++

    Thanks for your tipps guys

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •