# number-util

> Float to int bits and back

Latest version **1.0.3** (published 2014-06-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install number-util
pnpm add number-util
yarn add number-util
bun add number-util
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2014-06-12 |
| First published | 2013-12-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 10 |
| Author | Matt DesLauriers |
| Maintainers | mattdesl |
| Keywords | pow, npot, power, of, two, next, non, color, float, bits, int, rgba, argb, abgr, rgb, bgr |

## Links

- npm: https://www.npmjs.com/package/number-util
- Repository: https://github.com/mattdesl/number-util
- Issues: https://github.com/mattdesl/number-util/issues
- npm.io page: https://npm.io/package/number-util

## Alternatives

- [eslint-plugin-sonarjs](https://npm.io/package/eslint-plugin-sonarjs.md) — 2.9M weekly downloads
- [eslint-config-expo](https://npm.io/package/eslint-config-expo.md) — 1.5M weekly downloads
- [@matter/protocol](https://npm.io/package/@matter/protocol.md) — 63.5K weekly downloads
- [@eventcatalog/linter](https://npm.io/package/@eventcatalog/linter.md) — 24.8K weekly downloads
- [@inrupt/eslint-config-base](https://npm.io/package/@inrupt/eslint-config-base.md) — 4.5K weekly downloads

## Recent versions

- 1.0.3 (latest) — 2014-06-12
- 1.0.2 — 2014-01-19
- 1.0.1 — 2013-12-08

## README

# number-util

The following methods are exported:

- `intBitsToFloat`
	- Returns a float for the given int bits.
- `floatToIntBits`
	- Returns int bits for the given float.
- `intToFloatColor`
	- Returns a single float representing the 
	given ABGR integer. Some precision is lost.
- `colorToFloat`
	- Returns a single float representing the
	given R, G, B, and A bytes (0 - 255). Some precision is lost.
- `isPowerOfTwo`
	- Returns true if the number is a power-of-two size
- `nextPowerOfTwo`
	- Returns the next highest power-of-two size from the given number

# example

```javascript
var util = require('number-util');

//packs the RGBA color red into a single float
var color = util.colorToFloat(255, 0, 0, 255);
```

# use

In WebGL, it's often desirable to pack RGBA data into a single float to reduce buffer upload bandwidth, at the expense of some precision loss. 

# how

Typed arrays are used to perform the casting.

---
_Source: https://npm.io/package/number-util · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
