Allow negative values for float and double

This commit is contained in:
pyoor 2017-06-28 12:01:19 -07:00
parent 0a21e8ecb1
commit b1e9ec82c5

View file

@ -43,7 +43,8 @@ make.typed = {
*/ */
float: function (limit = null) { float: function (limit = null) {
let base = (limit !== null) ? random.number(limit) : random.number() let base = (limit !== null) ? random.number(limit) : random.number()
return 'new Float32Array([' + (base + random.float()) + '])[0]' let value = random.chance(10) ? -(base + random.float()) : (base + random.float())
return 'new Float32Array([' + value + '])[0]'
}, },
unrestrictedFloat: function (limit = null) { unrestrictedFloat: function (limit = null) {
if (random.chance(100)) { if (random.chance(100)) {
@ -55,14 +56,16 @@ make.typed = {
}, },
double: function (limit = null) { double: function (limit = null) {
let base = (limit !== null) ? random.number(limit) : random.number() let base = (limit !== null) ? random.number(limit) : random.number()
return 'new Float64Array([' + (base + random.float()) + '])[0]' let value = random.chance(10) ? -(base + random.float()) : (base + random.float())
return 'new Float64Array([' + value + '])[0]'
}, },
unrestrictedDouble: function (limit = null) { unrestrictedDouble: function (limit = null) {
if (random.chance(100)) { if (random.chance(100)) {
return random.pick([NaN, +Infinity, -Infinity]) return random.pick([NaN, +Infinity, -Infinity])
} else { } else {
let base = (limit !== null) ? random.number(limit) : random.number() let base = (limit !== null) ? random.number(limit) : random.number()
return 'new Float64Array([' + (base + random.float()) + '])[0]' let value = random.chance(10) ? -(base + random.float()) : (base + random.float())
return 'new Float64Array([' + value + '])[0]'
} }
}, },
any: function () { any: function () {