Closed nivida closed 5 years ago
You cannot use ieee 754 numbers that require more than 53 bits of mantissa. This has been the case in ethers since version 0, years ago. :)
Numbers larger than Number.MAX_SAFE_INTEGER are not tightly packed, so will be imprecise, leading to 50% of the time having dust, 50% being too small.
To solve this, keep in mind to use strings (decimal or 0x prefixed hex) and do all math using big numbers.
Here is some documentation: https://docs.ethers.io/ethers.js/html/notes.html#why-can-t-i-just-use-numbers
10e16 is about the cut off point, since it is 2 ** 53, which is the mantissa limit for 64 bit floating points.
This is a very intentional feature, not a bug. ;)
Closing this now, but please feel free to add comments and ask questions. Or re-open if you would like to bring more attention to this for other watchers to contribute to. :)
Thanks! :)
@ricmoo Thanks for the detailed information I will read your documentation 💪
@ricmoo.
I have this issue of bigNumber and it only perculiar with ios devices. My code is working smoothly with android, windows except ios. here is the error in iOS devices--> Error: invalid BigNumber string (argument="value", value="NaN", code=INVALID_ARGUMENT, version=bignumber/5.4.1) The value is always "NaN. no matter how I did it. I have tried everything all suggestion I read here. all of them are working very smoothly in android and windows . iOS is a big issue. please can you check?
let date = (new Date(date_time)).getTime(); //date_time is a dateString in the form of "2022-04-12 19:00:00"
const matchdate = BigNumber.from(date).div(1000);
console.log("MatchDate",matchdate);
await contract.stakeTeam(fixtureId,team_side,selectedId,localteam_id,visitorteam_id,matchdate,700);
This snippet above is pretty much working in android and windows except iOS. However, if I replace matchdate with a static number e.g await contract.stakeTeam(fixtureId,team_side,selectedId,localteam_id,visitorteam_id,1649786400,700); it works perfectly. I am so confused as this is really not happening across all OS.
As already discussed here in the Web3.js issue: https://github.com/ethereum/web3.js/issues/2077 does the new AbiCoder have problems with converting numbers to BigNumbers and encoding them correctly.
Because Web3.js is just passing the value to the ABI coder does this looks like an issue of ethers.js.
@ricmoo Do you have any additional information about this?