exact string matches return score as a very small floating point number, not exactly 0
See original GitHub issuescore: 2.220446049250313e-16 when I am comparing two identical strings, and searching by key I’m using typescript and fuse.js@6.4.6
const options = {
includeScore: true,
threshold: 0.1,
keys: ["name"],
};
const results = (new Fuse([{name: 'a'}], options)).search('a');
console.log(results[0].score === 0) // false, because score is 2.220446049250313e-16
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Comparing floating point number to zero - c++ - Stack Overflow
If you're comparing zero( y ) to another really small value( x ), say 1e-8, ... That's because floating point numbers are no...
Read more >What Every Computer Scientist Should Know About Floating ...
There are two reasons why a real number might not be exactly representable as a floating-point number. The most common situation is illustrated...
Read more >4.8 — Floating point numbers - Learn C++
Floating point numbers often have small rounding errors, even when the number has fewer significant digits than the precision. Many times these ...
Read more >decimal — Decimal fixed point and floating point arithmetic ...
The exactness carries over into arithmetic. In decimal floating point, 0.1 + 0.1 + 0.1 - 0.3 is exactly equal to zero. In...
Read more >Floating point numbers - Manual - PHP
If the string is numeric or leading numeric then it will resolve to the corresponding float value, otherwise it is converted to zero...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
According to the docs, by default if a perfect match is found then the search ceases to continue unless specifically setting findAllMatches to true. If you would like to do it manually, the docs also state that a score for an exact match is 0. Neither of these things is true regardless of the scoring theory.
I’m not saying this needs to change (although findAllMatches does seem redundant at this point and exact matching is inconsistent at best), but the docs certainly need to be updated, otherwise I can completely understand why people are treating this as a bug.
https://fusejs.io/api/options.html#findallmatches https://fusejs.io/api/options.html#includescore
I’d see this as a bug. I am facing the same issue and therefore findAllMatches isn’t working as it never finds an exact match!