1.0.0 • Published 9 years ago

compute-intmax v1.0.0

Weekly downloads
8
License
MIT
Repository
github
Last release
9 years ago

intmax

NPM version Build Status Coverage Status Dependencies

Returns the maximum value of a specified integer type.

Installation

$ npm install compute-intmax

For use in the browser, use browserify.

Usage

var intmax = require( 'compute-intmax' );

intmax( type )

Returns the maximum value of a specified integer type.

var max = intmax( 'int8' );
// returns 127

The following integer types are supported:

  • __int8__: signed 8-bit integer
  • uint8: unsigned 8-bit integer
  • int16: signed 16-bit integer
  • uint16: unsigned 16-bit integer
  • int32: signed 32-bit integer
  • uint32: unsigned 32-bit integer

If not provided an integer type, the function returns the maximum signed 32-bit integer.

intmax() === intmax( 'int32' );
// returns true

Examples

var intmax = require( 'compute-intmax' ),
	max;

// int32 (default):
max = intmax();
// returns 2147483647

// int8:
max = intmax( 'int8' );
// returns 127

// int16:
max = intmax( 'int16' );
// returns 32767

// int32:
max = intmax( 'int32' );
// returns 2147483647

// uint8:
max = intmax( 'uint8' );
// returns 255

// uint16:
max = intmax( 'uint16' );
// returns 65535

// uint32:
max = intmax( 'uint32' );
// returns 4294967295

To run the example code from the top-level application directory,

$ node ./examples/index.js

Tests

Unit

Unit tests use the Mocha test framework with Chai assertions. To run the tests, execute the following command in the top-level application directory:

$ make test

All new feature development should have corresponding unit tests to validate correct functionality.

Test Coverage

This repository uses Istanbul as its code coverage tool. To generate a test coverage report, execute the following command in the top-level application directory:

$ make test-cov

Istanbul creates a ./reports/coverage directory. To access an HTML version of the report,

$ make view-cov

License

MIT license.

Copyright

Copyright © 2015. The Compute.io Authors.