Skip to content

Vitest considers -0 and +0 to be different values #7667

@psychedelicious

Description

@psychedelicious

Describe the bug

I have a utility that may return -0.

This is technically a distinct value from +0, but per IEEE_754, "negative zero" and "positive zero" should be considered to be equal in numerical comparisons.

But vitest's .toBe() and .toEqual() methods appears to not consider them to be equal, causing unit tests to fail.

Reproduction

https://stackblitz.com/edit/vitest-dev-vitest-dgy7dtwc?file=test%2Fbasic.test.ts

System Info

The issue is reproduced in StackBlitz above, but here is my system info.

  System:
    OS: Linux 6.8 Ubuntu 22.04.4 LTS 22.04.4 LTS (Jammy Jellyfish)
    CPU: (20) x64 13th Gen Intel(R) Core(TM) i5-13600K
    Memory: 19.04 GB / 31.12 GB
    Container: Yes
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 20.13.1 - ~/.nvm/versions/node/v20.13.1/bin/node
    Yarn: 1.22.22 - ~/.nvm/versions/node/v20.13.1/bin/yarn
    npm: 10.5.2 - ~/.nvm/versions/node/v20.13.1/bin/npm
    pnpm: 8.15.9 - ~/.nvm/versions/node/v20.13.1/bin/pnpm
  npmPackages:
    @vitejs/plugin-react-swc: ^3.8.0 => 3.8.0 
    @vitest/coverage-v8: ^3.0.6 => 3.0.6 
    @vitest/ui: ^3.0.6 => 3.0.6 
    vite: ^6.1.0 => 6.1.0 
    vitest: ^3.0.6 => 3.0.6

Used Package Manager

pnpm

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    p2-nice-to-haveNot breaking anything but nice to have (priority)

    Type

    No type

    Projects

    Status

    Approved

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions