View Issue Details

IDProjectCategoryView StatusLast Update
0000429LDMud 3.3Efunspublic2007-10-06 19:55
Reporterford Assigned Tolars 
PrioritynormalSeverityfeatureReproducibilityalways
Status closedResolutionwon't fix 
Summary0000429: to_int() will not accept object type paramater.
Descriptionto_int() will not accept type object. Casts of object to int fail.

nul object = 0
non-nul = (!0)


Additional InformationSYNOPSIS
        int to_int(string)
        int to_int(float)
        int to_int(int)
        int to_int(closure)

        (int)<value>

DESCRIPTION
        Floats are truncated to integer values, strings with leadings
        digits are converted to integers up to the first non-digit.
        lfun-closures are converted into their function index,
        variable closure are converted into their variable index.
        Integers are just returned.

        Regarding floats, it is important to keep rounding effects
        in mind: to_int(3.1*10.0) does not return 31, but instead 30,
        because internally the result of the multiplication is 30.999999 .

BUGS
        The cast notation only works if the precise type of <value>
        is known at compile-time. This will not be fixed - use the
        function form instead.

HISTORY
        Introduced in 3.2.1@2

SEE ALSO
        to_string(E), sscanf(E)

TagsNo tags attached.

Activities

lars

2006-03-01 12:32

reporter   ~0000480

Well, there isn't exactly a good way to convert an object into a number.

ford

2006-03-03 06:33

reporter   ~0000486

Last edited: 2006-03-03 06:36

int to_int(object obj) {
  if (obj == NULL)
    return 0;
  else
    return (!0);
}

ford

2006-03-03 06:35

reporter   ~0000487

Last edited: 2006-03-03 06:36

int to_int(object obj) {
  if (obj == NULL)
    return 0;
  else
    return (int)obj;
}

ford

2006-03-03 06:40

reporter   ~0000488

Last edited: 2006-03-03 06:44

This is only needed to tell if an object is void or not, for "if" statments. I dont care what the value is just whether or not it's void.

I dont care about to_int(), except typecasts seem to use to_int().

Gnomi

2006-03-03 06:48

manager   ~0000489

Hmm, why don't you just use the object directly (if(ob) ...)?
To get an integer, that shows the existence of an object, you can use:
  int i = ob && 1;

ford

2006-03-08 23:18

reporter   ~0000493

Because when you do "if (ob)", the ob is automaticlly typecast to int, and ldmud uses to_int() when typecasting to integers.

lars

2006-03-08 23:35

reporter   ~0000494

This is not a bug.

While C does casts values to numbers when it requires a yes/no decision, even that is not a typecast, but a reinterpret_cast: if ("0") will evaluate to true.

LPC does what could be called a conversion to boolean, which for everything but numbers results in a check if the expression has a value at all:

  string s;
  if (s) --> false
  s = "";
  if (s) --> true

It could be done differently (and other languages do), but this way LPC gives you an easy way to check whether a variable has been set or not.

Issue History

Date Modified Username Field Change
2005-12-30 23:22 ford New Issue
2006-03-01 12:32 lars Note Added: 0000480
2006-03-03 06:33 ford Note Added: 0000486
2006-03-03 06:35 ford Note Added: 0000487
2006-03-03 06:36 ford Note Edited: 0000486
2006-03-03 06:36 ford Note Edited: 0000487
2006-03-03 06:36 ford Note Edited: 0000487
2006-03-03 06:40 ford Note Added: 0000488
2006-03-03 06:44 ford Note Edited: 0000488
2006-03-03 06:48 Gnomi Note Added: 0000489
2006-03-08 23:18 ford Note Added: 0000493
2006-03-08 23:35 lars Status new => resolved
2006-03-08 23:35 lars Resolution open => won't fix
2006-03-08 23:35 lars Assigned To => lars
2006-03-08 23:35 lars Note Added: 0000494
2007-10-06 19:55 lars Status resolved => closed