Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Vec\range handles ints which don't roundtrip through floats wrong #422

Open
lexidor opened this issue Sep 28, 2023 · 0 comments
Open
Assignees
Labels
Priority: Medium This issue may be useful, and needs some attention. Status: Accepted It's clear what the subject of the issue is about, and what the resolution should be. Status: Available No one has claimed responsibility for resolving this issue. Type: Bug Inconsistencies or issues which will cause an issue or problem for users or implementors.

Comments

@lexidor
Copy link

lexidor commented Sep 28, 2023

Describe the bug
When the arguments $start and $end to Vec\range(...) are ints exceeding the max safe integer for a 64-bit double, this function may return a vec (list-like array) of length one because of floating point imprecision.

To Reproduce

var_dump(Vec\range(1 << 60, (1 << 60) + 8));

array(1) {
  [0]=>
  int(1152921504606846976)
}

Expected behavior

array(9) {
  [0]=>
  int(1152921504606846976)
  [1]=>
  int(1152921504606846977)
  [2]=>
  int(1152921504606846978)
  [3]=>
  int(1152921504606846979)
  [4]=>
  int(1152921504606846980)
  [5]=>
  int(1152921504606846981)
  [6]=>
  int(1152921504606846982)
  [7]=>
  int(1152921504606846983)
  [8]=>
  int(1152921504606846984)
}

Environment (please complete the following information):

  • OS: 3v4l.org (Linux?)
  • PHP version: 8.0 through 8.2.10
  • Version: 2.7

Additional context
Casting an int to a float may truncate the number. So this if() considers some large integers (or hugely negative integers) to be equal when they are not.

    if ((float) $start === (float) $end) {
        return [$start];
    }
@lexidor lexidor added the Type: Bug Inconsistencies or issues which will cause an issue or problem for users or implementors. label Sep 28, 2023
@azjezz azjezz added Priority: Medium This issue may be useful, and needs some attention. Status: Accepted It's clear what the subject of the issue is about, and what the resolution should be. Status: Available No one has claimed responsibility for resolving this issue. labels Sep 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority: Medium This issue may be useful, and needs some attention. Status: Accepted It's clear what the subject of the issue is about, and what the resolution should be. Status: Available No one has claimed responsibility for resolving this issue. Type: Bug Inconsistencies or issues which will cause an issue or problem for users or implementors.
Projects
None yet
Development

No branches or pull requests

2 participants