Skip to content

Improve seq() consistency between integer/integer64 #211

@MichaelChirico

Description

@MichaelChirico

I think this is not desirable:

seq(as.integer64(1), 10, by=1.5)
# integer64
#  [1] 1  2  3  4  5  6  7  8  9  10
seq(1, 10, by=1.5)
# [1]  1.0  2.5  4.0  5.5  7.0  8.5 10.0

The trouble is that we can't always embed into double from integer64:

seq(as.integer64(2^60), by=1L, length.out=10L)
# integer64
#  [1] 1152921504606846976 1152921504606846977 1152921504606846978
#  [4] 1152921504606846979 1152921504606846980 1152921504606846981
#  [7] 1152921504606846982 1152921504606846983 1152921504606846984
# [10] 1152921504606846985

sprintf("%18.f", seq(2^60, by=1L, length.out=10L))
#  [1] "1152921504606846976" "1152921504606846976" "1152921504606846976"
#  [4] "1152921504606846976" "1152921504606846976" "1152921504606846976"
#  [7] "1152921504606846976" "1152921504606846976" "1152921504606846976"
# [10] "1152921504606846976"

That said, the seq() output is entirely determined by from, to, and by; we can cheaply examine these up front and determine if the output sequence embeds entirely in (1) integer64; (2) double; (3) neither.

Then we should determine the output as follows:

  1. Return integer64
  2. Return double
  3. Warn, and return integer64

Metadata

Metadata

Assignees

No one assigned

    Labels

    consistency⚠️ Breaking changeIssues whose solution requires a back-incompatible change to the public API

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions