jed-users mailing list

[2009 Date Index] [2009 Thread Index] [Other years]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]

Re: integer to string


Hi Frank,

How can an integer of more than 10 digits be converted to a string? string(123456789012) -1097262572
    string(12345678901)    -539222987
    string(1234567890)     1234567890

The problem is not the string conversion, but the integer representation itself. The literal constant 123456789012 does not define what you think it should, because the underlying Integer_Type is not capable of carrying such a large number.

It seems that you're not using a very recent version of S-Lang (<2.2), because S-Lang >= pre2.2.0-39 issues a warning in this case:
Integer overflow detected: too many digits

If you really have to deal with such integer numbers, you may consider to use the LLong_Type, which is declared in literal constants with an LL-postfix:
   string(123456789012LL)  ->  "123456789012"
However, there is also a limit for this data type, which is 2^63 on my system:
  variable a = 9223372036854775807LL;
  string(a);  % "9223372036854775807"
  a++;
  string(a);  % "-9223372036854775808"

Admittedly, one can still go for unsigned long long, reaching to 2^64...
  variable a = 18446744073709551615ULL;
  string(a);  % "18446744073709551615"
  a++;
  string(a);  % "0"

Cheers,

Manfred

jed version: 0.99.19/Unix
S-Lang version: 2.2.2

--------------------------
To unsubscribe send email to <jed-users-request@xxxxxxxxxxx> with
the word "unsubscribe" in the message body.
Need help? Email <jed-users-owner@xxxxxxxxxxx>.


[2009 date index] [2009 thread index]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]