Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/constants/numerical.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = {
* to avoid glitches: Make sure that even when you multiply it by the
* number of pixels on a giant screen it still works
*/
FP_SAFE: Number.MAX_VALUE / 10000,
FP_SAFE: Number.MAX_VALUE * 1e-4,

/*
* conversion of date units to milliseconds
Expand Down
6 changes: 3 additions & 3 deletions src/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ var utcFormat = require('d3-time-format').utcFormat;
var isNumeric = require('fast-isnumeric');

var numConstants = require('../constants/numerical');
var FP_SAFE = numConstants.FP_SAFE;
var MAX_SAFE = numConstants.FP_SAFE;
var MIN_SAFE = -MAX_SAFE;
var BADNUM = numConstants.BADNUM;

var lib = module.exports = {};
Expand Down Expand Up @@ -166,8 +167,7 @@ lib.cleanNumber = require('./clean_number');
lib.ensureNumber = function ensureNumber(v) {
if(!isNumeric(v)) return BADNUM;
v = Number(v);
if(v < -FP_SAFE || v > FP_SAFE) return BADNUM;
return isNumeric(v) ? Number(v) : BADNUM;
return (v > MAX_SAFE || v < MIN_SAFE) ? BADNUM : v;
};

/**
Expand Down