Browse Source

add type Int53

master
Daniel Cousens 6 years ago
parent
commit
923a4376f6
  1. 11
      extra.js
  2. 8
      scripts/generate_tests.js
  3. 1039
      test/fixtures.json
  4. 1
      test/types.js

11
extra.js

@ -39,7 +39,7 @@ function Range (a, b, f) {
return _range return _range
} }
var UINT53_MAX = Math.pow(2, 53) - 1 var INT53_MAX = Math.pow(2, 53) - 1
function Finite (value) { function Finite (value) {
return typeof value === 'number' && isFinite(value) return typeof value === 'number' && isFinite(value)
@ -47,13 +47,19 @@ function Finite (value) {
function Int8 (value) { return ((value << 24) >> 24) === value } function Int8 (value) { return ((value << 24) >> 24) === value }
function Int16 (value) { return ((value << 16) >> 16) === value } function Int16 (value) { return ((value << 16) >> 16) === value }
function Int32 (value) { return (value | 0) === value } function Int32 (value) { return (value | 0) === value }
function Int53 (value) {
return typeof value === 'number' &&
value >= -INT53_MAX &&
value <= INT53_MAX &&
Math.floor(value) === value
}
function UInt8 (value) { return (value & 0xff) === value } function UInt8 (value) { return (value & 0xff) === value }
function UInt16 (value) { return (value & 0xffff) === value } function UInt16 (value) { return (value & 0xffff) === value }
function UInt32 (value) { return (value >>> 0) === value } function UInt32 (value) { return (value >>> 0) === value }
function UInt53 (value) { function UInt53 (value) {
return typeof value === 'number' && return typeof value === 'number' &&
value >= 0 && value >= 0 &&
value <= UINT53_MAX && value <= INT53_MAX &&
Math.floor(value) === value Math.floor(value) === value
} }
@ -67,6 +73,7 @@ var types = {
Int8: Int8, Int8: Int8,
Int16: Int16, Int16: Int16,
Int32: Int32, Int32: Int32,
Int53: Int53,
Range: Range, Range: Range,
StringN: _StringN, StringN: _StringN,
UInt8: UInt8, UInt8: UInt8,

8
scripts/generate_tests.js

@ -61,6 +61,8 @@ const VALUES2 = [
{ a: 'foo', b: { c: 'bar' } } { a: 'foo', b: { c: 'bar' } }
] ]
const INT53_MAX = Math.pow(2, 53) - 1
// extra // extra
const VALUESX = [ const VALUESX = [
'fff', 'fff',
@ -77,8 +79,10 @@ const VALUESX = [
0xffff, 0xffff,
0x10000, 0x10000,
0xffffffff, 0xffffffff,
9007199254740991, INT53_MAX,
9007199254740994 INT53_MAX + 3,
-INT53_MAX,
-INT53_MAX - 3
] ]
const fixtures = { const fixtures = {

1039
test/fixtures.json

File diff suppressed because it is too large

1
test/types.js

@ -44,6 +44,7 @@ module.exports = {
'Int8': typeforce.Int8, 'Int8': typeforce.Int8,
'Int16': typeforce.Int16, 'Int16': typeforce.Int16,
'Int32': typeforce.Int32, 'Int32': typeforce.Int32,
'Int53': typeforce.Int53,
'UInt8': typeforce.UInt8, 'UInt8': typeforce.UInt8,
'UInt16': typeforce.UInt16, 'UInt16': typeforce.UInt16,
'UInt32': typeforce.UInt32, 'UInt32': typeforce.UInt32,

Loading…
Cancel
Save