question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

exact string matches return score as a very small floating point number, not exactly 0

See original GitHub issue

score: 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:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
ljones-i-nexuscommented, May 24, 2021

For better or worse, this is by design. Take a look at the scoring theory to understand why.

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

2reactions
dodlhuatcommented, Apr 2, 2021

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!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found