This commit is contained in:
chrosey
2017-09-13 07:52:34 +02:00
parent a1f16c37f4
commit 2340b0226b
24621 changed files with 2912161 additions and 149 deletions
+7
View File
@@ -0,0 +1,7 @@
language: node_js
node_js:
- 'node'
env:
global:
- secure: f3NrmOV/A7oACn47J1mkIpH8Sn/LINtluZvo/9pGo3Ss4+D2lyt7UawpedHtnYgU9WEyjPSi7pDWopUrIzusQ2trLYRJr8WAOEyHlgaepDyy4BW3ghGMKHMsS05kilYLP8nu1sRd6y1AcUYKw+kUrrSPanI7kViWVQ5d5DuwXO8=
- secure: a6teILh33z5fbGQbh5/EkFfAyXfa2fPJG1upy9K+jLAbG4WZxXD+YmXG9Tz33/2NJm6UplGfTJ8IQEXgxEfAFk3ao3xfKxzm3i64XxtroSlXIFNSiQKogxDfLEtWDoNNCodPHaV3ATEqxGJ5rkkUeU1+ROWW0sjG5JR26k8/Hfg=
+20
View File
@@ -0,0 +1,20 @@
ui: tape
scripts:
- "./test/_polyfill.js"
browsers:
- name: chrome
version: latest
- name: firefox
version: latest
- name: safari
version: latest
- name: ie
version: 11
- name: microsoftedge
version: latest
- name: opera
version: latest
- name: android
version: latest
- name: iphone
version: latest
+28
View File
@@ -0,0 +1,28 @@
Copyright (c) 2008, Fair Oaks Labs, Inc.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of Fair Oaks Labs, Inc. nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
+47
View File
@@ -0,0 +1,47 @@
# ieee754 [![travis][travis-image]][travis-url] [![npm][npm-image]][npm-url] [![downloads][downloads-image]][npm-url]
[![saucelabs][saucelabs-image]][saucelabs-url]
[travis-image]: https://img.shields.io/travis/feross/ieee754/master.svg
[travis-url]: https://travis-ci.org/feross/ieee754
[npm-image]: https://img.shields.io/npm/v/ieee754.svg
[npm-url]: https://npmjs.org/package/ieee754
[downloads-image]: https://img.shields.io/npm/dm/ieee754.svg
[saucelabs-image]: https://saucelabs.com/browser-matrix/ieee754.svg
[saucelabs-url]: https://saucelabs.com/u/ieee754
### Read/write IEEE754 floating point numbers from/to a Buffer or array-like object.
## install
```
npm install ieee754
```
## methods
`var ieee754 = require('ieee754')`
The `ieee754` object has the following functions:
```
ieee754.read = function (buffer, offset, isLE, mLen, nBytes)
ieee754.write = function (buffer, value, offset, isLE, mLen, nBytes)
```
The arguments mean the following:
- buffer = the buffer
- offset = offset into the buffer
- value = value to set (only for `write`)
- isLe = is little endian?
- mLen = mantissa length
- nBytes = number of bytes
## what is ieee754?
The IEEE Standard for Floating-Point Arithmetic (IEEE 754) is a technical standard for floating-point computation. [Read more](http://en.wikipedia.org/wiki/IEEE_floating_point).
## license
BSD 3 Clause. Copyright (c) 2008, Fair Oaks Labs, Inc.
+84
View File
@@ -0,0 +1,84 @@
exports.read = function (buffer, offset, isLE, mLen, nBytes) {
var e, m
var eLen = nBytes * 8 - mLen - 1
var eMax = (1 << eLen) - 1
var eBias = eMax >> 1
var nBits = -7
var i = isLE ? (nBytes - 1) : 0
var d = isLE ? -1 : 1
var s = buffer[offset + i]
i += d
e = s & ((1 << (-nBits)) - 1)
s >>= (-nBits)
nBits += eLen
for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {}
m = e & ((1 << (-nBits)) - 1)
e >>= (-nBits)
nBits += mLen
for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {}
if (e === 0) {
e = 1 - eBias
} else if (e === eMax) {
return m ? NaN : ((s ? -1 : 1) * Infinity)
} else {
m = m + Math.pow(2, mLen)
e = e - eBias
}
return (s ? -1 : 1) * m * Math.pow(2, e - mLen)
}
exports.write = function (buffer, value, offset, isLE, mLen, nBytes) {
var e, m, c
var eLen = nBytes * 8 - mLen - 1
var eMax = (1 << eLen) - 1
var eBias = eMax >> 1
var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0)
var i = isLE ? 0 : (nBytes - 1)
var d = isLE ? 1 : -1
var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0
value = Math.abs(value)
if (isNaN(value) || value === Infinity) {
m = isNaN(value) ? 1 : 0
e = eMax
} else {
e = Math.floor(Math.log(value) / Math.LN2)
if (value * (c = Math.pow(2, -e)) < 1) {
e--
c *= 2
}
if (e + eBias >= 1) {
value += rt / c
} else {
value += rt * Math.pow(2, 1 - eBias)
}
if (value * c >= 2) {
e++
c /= 2
}
if (e + eBias >= eMax) {
m = 0
e = eMax
} else if (e + eBias >= 1) {
m = (value * c - 1) * Math.pow(2, mLen)
e = e + eBias
} else {
m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen)
e = 0
}
}
for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
e = (e << mLen) | m
eLen += mLen
for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
buffer[offset + i - d] |= s * 128
}
+105
View File
@@ -0,0 +1,105 @@
{
"_args": [
[
{
"raw": "ieee754@^1.1.4",
"scope": null,
"escapedName": "ieee754",
"name": "ieee754",
"rawSpec": "^1.1.4",
"spec": ">=1.1.4 <2.0.0",
"type": "range"
},
"c:\\xampp\\htdocs\\laravel\\node_modules\\buffer"
]
],
"_from": "ieee754@>=1.1.4 <2.0.0",
"_id": "ieee754@1.1.8",
"_inCache": true,
"_location": "/ieee754",
"_nodeVersion": "6.7.0",
"_npmOperationalInternal": {
"host": "packages-12-west.internal.npmjs.com",
"tmp": "tmp/ieee754-1.1.8.tgz_1475481601035_0.6688473029062152"
},
"_npmUser": {
"name": "feross",
"email": "feross@feross.org"
},
"_npmVersion": "3.10.3",
"_phantomChildren": {},
"_requested": {
"raw": "ieee754@^1.1.4",
"scope": null,
"escapedName": "ieee754",
"name": "ieee754",
"rawSpec": "^1.1.4",
"spec": ">=1.1.4 <2.0.0",
"type": "range"
},
"_requiredBy": [
"/buffer"
],
"_resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.1.8.tgz",
"_shasum": "be33d40ac10ef1926701f6f08a2d86fbfd1ad3e4",
"_shrinkwrap": null,
"_spec": "ieee754@^1.1.4",
"_where": "c:\\xampp\\htdocs\\laravel\\node_modules\\buffer",
"author": {
"name": "Feross Aboukhadijeh",
"email": "feross@feross.org",
"url": "http://feross.org"
},
"bugs": {
"url": "https://github.com/feross/ieee754/issues"
},
"contributors": [
{
"name": "Romain Beauxis",
"email": "toots@rastageeks.org"
}
],
"dependencies": {},
"description": "Read/write IEEE754 floating point numbers from/to a Buffer or array-like object",
"devDependencies": {
"standard": "*",
"tape": "^4.0.0",
"zuul": "^3.0.0"
},
"directories": {},
"dist": {
"shasum": "be33d40ac10ef1926701f6f08a2d86fbfd1ad3e4",
"tarball": "https://registry.npmjs.org/ieee754/-/ieee754-1.1.8.tgz"
},
"gitHead": "53d3f869cc527852156b8307353c55addc3e03ae",
"homepage": "https://github.com/feross/ieee754#readme",
"keywords": [
"IEEE 754",
"buffer",
"convert",
"floating point",
"ieee754"
],
"license": "BSD-3-Clause",
"main": "index.js",
"maintainers": [
{
"name": "feross",
"email": "feross@feross.org"
}
],
"name": "ieee754",
"optionalDependencies": {},
"readme": "ERROR: No README data found!",
"repository": {
"type": "git",
"url": "git://github.com/feross/ieee754.git"
},
"scripts": {
"test": "standard && npm run test-node && npm run test-browser",
"test-browser": "zuul -- test/*.js",
"test-browser-local": "zuul --local -- test/*.js",
"test-node": "tape test/*.js"
},
"version": "1.1.8"
}
+23
View File
@@ -0,0 +1,23 @@
var ieee754 = require('../')
var test = require('tape')
var EPSILON = 0.00001
test('read float', function (t) {
var buf = new Buffer(4)
buf.writeFloatLE(42.42, 0)
var num = ieee754.read(buf, 0, true, 23, 4)
t.ok(Math.abs(num - 42.42) < EPSILON)
t.end()
})
test('write float', function (t) {
var buf = new Buffer(4)
ieee754.write(buf, 42.42, 0, true, 23, 4)
var num = buf.readFloatLE(0)
t.ok(Math.abs(num - 42.42) < EPSILON)
t.end()
})