3 [![npm](https://img.shields.io/npm/v/@protobufjs/float.svg)](https://www.npmjs.com/package/@protobufjs/float)
\r
5 Reads / writes floats / doubles from / to buffers in both modern and ancient browsers. Fast.
\r
10 * **writeFloatLE(val: `number`, buf: `Uint8Array`, pos: `number`)**<br />
\r
11 Writes a 32 bit float to a buffer using little endian byte order.
\r
13 * **writeFloatBE(val: `number`, buf: `Uint8Array`, pos: `number`)**<br />
\r
14 Writes a 32 bit float to a buffer using big endian byte order.
\r
16 * **readFloatLE(buf: `Uint8Array`, pos: `number`): `number`**<br />
\r
17 Reads a 32 bit float from a buffer using little endian byte order.
\r
19 * **readFloatBE(buf: `Uint8Array`, pos: `number`): `number`**<br />
\r
20 Reads a 32 bit float from a buffer using big endian byte order.
\r
22 * **writeDoubleLE(val: `number`, buf: `Uint8Array`, pos: `number`)**<br />
\r
23 Writes a 64 bit double to a buffer using little endian byte order.
\r
25 * **writeDoubleBE(val: `number`, buf: `Uint8Array`, pos: `number`)**<br />
\r
26 Writes a 64 bit double to a buffer using big endian byte order.
\r
28 * **readDoubleLE(buf: `Uint8Array`, pos: `number`): `number`**<br />
\r
29 Reads a 64 bit double from a buffer using little endian byte order.
\r
31 * **readDoubleBE(buf: `Uint8Array`, pos: `number`): `number`**<br />
\r
32 Reads a 64 bit double from a buffer using big endian byte order.
\r
36 There is a simple benchmark included comparing raw read/write performance of this library (float), float's fallback for old browsers, the [ieee754](https://www.npmjs.com/package/ieee754) module and node's [buffer](https://nodejs.org/api/buffer.html). On an i7-2600k running node 6.9.1 it yields:
\r
39 benchmarking writeFloat performance ...
\r
41 float x 42,741,625 ops/sec ±1.75% (81 runs sampled)
\r
42 float (fallback) x 11,272,532 ops/sec ±1.12% (85 runs sampled)
\r
43 ieee754 x 8,653,337 ops/sec ±1.18% (84 runs sampled)
\r
44 buffer x 12,412,414 ops/sec ±1.41% (83 runs sampled)
\r
45 buffer (noAssert) x 13,471,149 ops/sec ±1.09% (84 runs sampled)
\r
48 float (fallback) was 73.5% slower
\r
49 ieee754 was 79.6% slower
\r
50 buffer was 70.9% slower
\r
51 buffer (noAssert) was 68.3% slower
\r
53 benchmarking readFloat performance ...
\r
55 float x 44,382,729 ops/sec ±1.70% (84 runs sampled)
\r
56 float (fallback) x 20,925,938 ops/sec ±0.86% (87 runs sampled)
\r
57 ieee754 x 17,189,009 ops/sec ±1.01% (87 runs sampled)
\r
58 buffer x 10,518,437 ops/sec ±1.04% (83 runs sampled)
\r
59 buffer (noAssert) x 11,031,636 ops/sec ±1.15% (87 runs sampled)
\r
62 float (fallback) was 52.5% slower
\r
63 ieee754 was 61.0% slower
\r
64 buffer was 76.1% slower
\r
65 buffer (noAssert) was 75.0% slower
\r
67 benchmarking writeDouble performance ...
\r
69 float x 38,624,906 ops/sec ±0.93% (83 runs sampled)
\r
70 float (fallback) x 10,457,811 ops/sec ±1.54% (85 runs sampled)
\r
71 ieee754 x 7,681,130 ops/sec ±1.11% (83 runs sampled)
\r
72 buffer x 12,657,876 ops/sec ±1.03% (83 runs sampled)
\r
73 buffer (noAssert) x 13,372,795 ops/sec ±0.84% (85 runs sampled)
\r
76 float (fallback) was 73.1% slower
\r
77 ieee754 was 80.1% slower
\r
78 buffer was 67.3% slower
\r
79 buffer (noAssert) was 65.3% slower
\r
81 benchmarking readDouble performance ...
\r
83 float x 40,527,888 ops/sec ±1.05% (84 runs sampled)
\r
84 float (fallback) x 18,696,480 ops/sec ±0.84% (86 runs sampled)
\r
85 ieee754 x 14,074,028 ops/sec ±1.04% (87 runs sampled)
\r
86 buffer x 10,092,367 ops/sec ±1.15% (84 runs sampled)
\r
87 buffer (noAssert) x 10,623,793 ops/sec ±0.96% (84 runs sampled)
\r
90 float (fallback) was 53.8% slower
\r
91 ieee754 was 65.3% slower
\r
92 buffer was 75.1% slower
\r
93 buffer (noAssert) was 73.8% slower
\r
102 **License:** [BSD 3-Clause License](https://opensource.org/licenses/BSD-3-Clause)
\r