-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,7 @@ | |
*/ | ||
|
||
if (process.env.NODE_ENV !== 'build') { | ||
var BigNumber = require('bignumber.js'); // jshint ignore:line | ||
var BigNumber = require('bn.js'); // jshint ignore:line | ||
} | ||
|
||
var utils = require('./utils'); | ||
|
@@ -45,17 +45,21 @@ var formatInputInt = function (value) { | |
if (value instanceof BigNumber || typeof value === 'number') { | ||
if (typeof value === 'number') | ||
value = new BigNumber(value); | ||
BigNumber.config(c.ETH_BIGNUMBER_ROUNDING_MODE); | ||
value = value.round(); | ||
//BigNumber.config(c.ETH_BIGNUMBER_ROUNDING_MODE); | ||
//value = value.round(); | ||
|
||
if (value.lessThan(0)) | ||
value = new BigNumber("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 16).plus(value).plus(1); | ||
if (value.cmpn(0) === -1) | ||
value = new BigNumber("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 16).add(value).add(new BigNumber(1)); | ||
value = value.toString(16); | ||
} | ||
else if (value.indexOf('0x') === 0) | ||
value = value.substr(2); | ||
else if (typeof value === 'string') | ||
value = formatInputInt(new BigNumber(value)); | ||
else if (typeof value === 'string') { | ||
if (value.indexOf('0x') === 0) { | ||
value = value.substr(2); | ||
} else { | ||
value = value.indexOf('.') === -1 ? value : value.substr(0, value.indexOf('.')); | ||
value = formatInputInt(new BigNumber(value)); | ||
} | ||
} | ||
else | ||
value = (+value).toString(16); | ||
return padLeft(value, padding); | ||
|
@@ -77,7 +81,7 @@ var formatInputBool = function (value) { | |
/// Values are multiplied by 2^m and encoded as integers | ||
/// @returns byte representation of real | ||
var formatInputReal = function (value) { | ||
return formatInputInt(new BigNumber(value).times(new BigNumber(2).pow(128))); | ||
return formatInputInt(new BigNumber(value).mul(new BigNumber(2).toRed(BigNumber.red('k256')).redPow(new BigNumber(128)).fromRed())); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is k256 ok for the max int? Do you have a max int that ethereum.js can handle defined somewhere? |
||
}; | ||
|
||
|
||
|
@@ -95,7 +99,7 @@ var formatOutputInt = function (value) { | |
// check if it's negative number | ||
// it it is, return two's complement | ||
if (signedIsNegative(value)) { | ||
return new BigNumber(value, 16).minus(new BigNumber('ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', 16)).minus(1); | ||
return new BigNumber(value, 16).sub(new BigNumber('ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', 16)).sub(new BigNumber(1)); | ||
} | ||
return new BigNumber(value, 16); | ||
}; | ||
|
@@ -109,12 +113,12 @@ var formatOutputUInt = function (value) { | |
|
||
/// @returns input bytes formatted to real | ||
var formatOutputReal = function (value) { | ||
return formatOutputInt(value).dividedBy(new BigNumber(2).pow(128)); | ||
return formatOutputInt(value).div(new BigNumber(2).toRed(BigNumber.red('k256')).redPow(new BigNumber(128)).fromRed()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe define There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also see this issue on a brief explention of reduction context indutny/bn.js#40 |
||
}; | ||
|
||
/// @returns input bytes formatted to ureal | ||
var formatOutputUReal = function (value) { | ||
return formatOutputUInt(value).dividedBy(new BigNumber(2).pow(128)); | ||
return formatOutputUInt(value).div(new BigNumber(2).toRed(BigNumber.red('k256')).redPow(new BigNumber(128)).fromRed()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and here |
||
}; | ||
|
||
/// @returns right-aligned input bytes formatted to hex | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be
value.cmpn(new BN(0))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you are right, I will fix this