Skip to content

Commit

Permalink
Simpler detector
Browse files Browse the repository at this point in the history
  • Loading branch information
dy committed Sep 14, 2023
1 parent 002d112 commit 8ee0f55
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,9 @@ const flt = input => {
input = input.replaceAll('_', '')

// 0x1.5p3
if (/^[+-]?0x/.test(input)) {
let sign = input[0] === '-' ? (input = input.slice(1), -1) : 1,
[sig, exp] = input.split(/p/i), [dec, fract] = sig.split('.')
sig = parseInt(dec) + (fract ? parseInt(fract, 16) / (16 ** fract.length) : 0)
if (input.includes('0x')) {
let [sig, exp] = input.split(/p/i), [dec, fract] = sig.split('.'), sign = dec[0] === '-' ? -1 : 1
sig = parseInt(dec) * sign + (fract ? parseInt(fract, 16) / (16 ** fract.length) : 0)
return sign * (exp ? sig * 2 ** parseInt(exp, 10) : sig);
}

Expand Down

0 comments on commit 8ee0f55

Please sign in to comment.