Skip to content

Use doubles instead of ints in R for igraph_integer_t #890

@szhorvat

Description

@szhorvat

Values which have type INTEGER in functions.yaml should be handled as type numeric, and not type integer, in R. This is so that we can support values greater than $2^{31}-1$.

This change needs to be done in:

  • Stimulus code generator
    • On the R side, use as.numeric instead of as.integer
    • On the C side, retrieve value as REAL (i.e. double type) instead of INTEGER, then converted to igraph_integer_t
    • When converting from a double to igraph_integer_t, we need to check that the following holds and throw an error otherwise:
      • The value fits in an igraph_integer_t, i.e. IGRAPH_INTEGER_MIN <= value && value <= IGRAPH_INTEGER_MAX.
      • The integer value was exactly representable in a double to start with. Check that the value is no greater than IGRAPH_MAX_EXACT_REAL. This constant is currently internal, found in cigraph/src/math/safe_intop.h.
  • Do the same as above for the hand-written code in rinterface_extra.c. Pay attention that for some functions, only the R code, or only the C code is auto-generated, but not both. Thus the update needs to be done simultaneously for the auto-generated code and the hand-written one.

I have already updated most of the hand-written code where possible, but I did not add overflow checks for the double -> igraph_integer_t conversion. This should be done as well, as the last step.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions