Jump to content

Processing Large Integers


SalvadorNL
 Share

You are about to reply to a thread that has been inactive for 943 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

its been a while since i last scripted, and this simple little thing is driving me crazy


 

Quote

 

  if ((integer)msg) { integer min = -2147483648; integer max = 2147483647; integer input = (integer)msg;
                                         if (((integer)msg > min & (integer)msg < max) & (string)input == (string)msg) {   llOwnerSay("New Channel: "+(string)msg);  }

 

 

If the user enters a number outside the scope,  the input will result in;  -1 ,  although this works,  i wonder if there isn't a better/cleaner option ?

Link to comment
Share on other sites

It depends on what you want to accomplish. If your goal is to get a channel for a listen hat is reasonably safe against duplication, there are better methods such as taking a portion of the user's UUID and converting that to a negative integer..

One safeguard you could try is to take the length of msg before trying to cast it to an integer and making sure it does not exceed the length of a string holding a maximum integer representation, and don't cast if the string is too long.

  • Like 1
Link to comment
Share on other sites

13 hours ago, Profaitchikenz Haiku said:

It depends on what you want to accomplish. If your goal is to get a channel for a listen hat is reasonably safe against duplication, there are better methods such as taking a portion of the user's UUID and converting that to a negative integer..

One safeguard you could try is to take the length of msg before trying to cast it to an integer and making sure it does not exceed the length of a string holding a maximum integer representation, and don't cast if the string is too long.

For example:

integer number;

number = llGetSubString(number, 0, 9);
number = -(llAbs(number));

 

Link to comment
Share on other sites

On 12/4/2021 at 5:19 PM, SalvadorNL said:

although this works,  i wonder if there isn't a better/cleaner option ?

LSL only has Signed 32-bit numbers, so trying to check if an integer value is outside of those bounds is impossible.

Your code would work even if you removed the min/max check, at which point your code is basically the same as KT's. Sadly that's about as short as it gets.

  • Like 1
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 943 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...