js-hexfloat
Advanced tools
Comparing version 0.1.0 to 0.2.0
@@ -12,13 +12,11 @@ /* | ||
} | ||
var RE_HEXFLOAT = | ||
/([\+\-]?)0x([0-9A-F]+).?([0-9A-F]*)p([\+\-]?[0-9]*)/i; | ||
// 1 2 3 4 | ||
var parseHexFloat = function(s) { | ||
// 1 2 3 4 5 | ||
var m = | ||
(/^([\+\-]?)0x([0-9A-Z]+).?([0-9A-Z]*)p([\+\-]?)([0-9]*)/i) | ||
.exec(s); | ||
var m = RE_HEXFLOAT.exec(s); | ||
if (!m) return NaN; | ||
var sign = m[1] == '-' ? -1 : 1; | ||
var mantissa = parseInt(m[2] + m[3], 16); | ||
var esign = m[4] == '-' ? -1 : 1; | ||
var exponent = esign * (m[5]|0) - 4*m[3].length; | ||
return sign * mantissa * Math.pow(2, exponent); | ||
var mantissa = parseInt(m[1] + m[2] + m[3], 16); | ||
var exponent = (m[4]|0) - 4*m[3].length; | ||
return mantissa * Math.pow(2, exponent); | ||
}; | ||
@@ -45,2 +43,3 @@ var toHexString = function(canonical) { | ||
[ Number, 'parseHexFloat', parseHexFloat], | ||
[ global, 'RE_HEXFLOAT', RE_HEXFLOAT], | ||
[ Number.prototype, 'toHexString', toHexString ] | ||
@@ -47,0 +46,0 @@ ].forEach(function(a){ |
{ | ||
"name": "js-hexfloat", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "Rudimentary C99 Hexadecimal Float Support in JS", | ||
@@ -5,0 +5,0 @@ "main": "hexfloat.js", |
@@ -27,2 +27,10 @@ [![build status](https://secure.travis-ci.org/dankogai/js-hexfloat.png)](http://travis-ci.org/dankogai/js-hexfloat) | ||
### `RE_HEXFLOAT` | ||
`RegExp` object used in `parseHexFloat`: | ||
````javascript | ||
/([\+\-]?)0x([0-9A-F]+).?([0-9A-F]*)p([\+\-]?[0-9]*)/i | ||
```` | ||
### `Number.prototype.toHexString(canonical)` | ||
@@ -29,0 +37,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
14378
61
97