Describe the bug
The lerp method may have accuracy problems when calculating with decimals, which may not matter in some scenarios (such as calculating pixels), but may be confusing in some situations.
// math.test.ts
import { lerp } from './math'
it('lerp', () => {
expect(lerp(0.2, 0.4, 0.5)).toMatchInlineSnapshot('0.30000000000000004')
})
Reproduction
https://github.com/CatsJuice/mir-antfu-utils-math-lerp-precision
System Info
System:
OS: macOS 14.0
CPU: (10) arm64 Apple M1 Pro
Memory: 67.19 MB / 16.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 18.16.0 - ~/.nvm/versions/node/v18.16.0/bin/node
Yarn: 1.22.17 - /usr/local/bin/yarn
npm: 9.5.1 - ~/.nvm/versions/node/v18.16.0/bin/npm
Browsers:
Safari: 17.0
Used Package Manager
pnpm
Validations
Describe the bug
The
lerpmethod may have accuracy problems when calculating with decimals, which may not matter in some scenarios (such as calculating pixels), but may be confusing in some situations.Reproduction
https://github.com/CatsJuice/mir-antfu-utils-math-lerp-precision
System Info
System: OS: macOS 14.0 CPU: (10) arm64 Apple M1 Pro Memory: 67.19 MB / 16.00 GB Shell: 5.9 - /bin/zsh Binaries: Node: 18.16.0 - ~/.nvm/versions/node/v18.16.0/bin/node Yarn: 1.22.17 - /usr/local/bin/yarn npm: 9.5.1 - ~/.nvm/versions/node/v18.16.0/bin/npm Browsers: Safari: 17.0Used Package Manager
pnpm
Validations