Comments (13)
I'll have a look at this later this week.
from big.js.
Okay, valueOf
now returns '-0'
for negative zero, which is clearly the right thing to do.
Thanks for the nudge.
from big.js.
As with JavaScript numbers, calling toString
on a Big whose value is minus zero will intentionally result in "0"
not "-0"
, but the value of the Big after rounding in your example will still actually be minus zero as can be seen from
new Big(-0.4).round(0).s // -1
from big.js.
Ok, got you. It's more a problem with the method of testing rather than the Big. I forgot about taking a look at the actual property to see what that was indicating. I didn't know that Big's toString
method intentionally mimicked Javascript's -0.toString()
result. I see in the tests that you normally use the private isMinusZero
function when you are being specific, but in this case you did not, so that left me wondering. Thank's for the quick reply.
from big.js.
I am wondering if it would make sense to have valueOf
, which returns the same as toString
, represent the value of the Big('-0')
as -0
?
from big.js.
String type or number type?
Clearly, valueOf
needs to return the same type each time, and I chose long ago that it needs to be string because of the usual precision loss in the conversion to number, which means that a returned number would not accurately represent the value of a Big.
So, if you're suggesting valueOf
return the string '-0'
, then yes that's an option, although strictly it would break backward compatibility because valueOf
would no longer return the same as toString
... i.e. it would mean the major version number would need to be incremented.
I notice that (-0).valueOf()
returns -0
(number type) on the browsers I've just checked, but 0
(number type) in Node.js.
from big.js.
Yes, I meant valueOf
to return the string '-0'
. It's just at present, other than looking at the properties of Big, there is no way to preserve this information - unless another method was added to the class. Anyway, it's just a suggestion. :)
from big.js.
Yes, I think it makes sense, and I will probably make the change to bignumber.js and decimal.js also if I make it here.
from big.js.
If you are going to do this then it may well be worth thinking about the toJSON
method too, would it be best to use the valueOf
or toString
representation. I'm initially thinking the valueOf
?
from big.js.
Added this ability along with tests to my fork, if it is of any interest. :)
from big.js.
I see that travis is keeping you busy :)
And yes, I think that toJSON
should use valueOf
to preserve the signed zero.
from big.js.
Yeah, that and some strange bug on node 0.6 in multiply that I don't understand, but managed to fix it by just changing how the code was written, (y.s * zero) changed to an if..else. Weird! :)
from big.js.
The valueOf
preservation of -0
made it into BigNumber.js, but I was just wondering if you plan to do the same in Big.js?
https://github.com/MikeMcl/big.js/blob/master/big.js#L877
from big.js.
Related Issues (20)
- Uncaught ReferenceError: Big is not defined HOT 2
- Circular dependency leads to error when recursively accessing enumerable properties HOT 1
- [Feature Request] Static properties for Comparisons HOT 1
- [Feature Request] Conversion between Big and BigInt HOT 2
- Performance of pow function HOT 2
- TS7016: Could not find a declaration file for module 'big.js' HOT 2
- rounding 9.9 gives improper coefficient HOT 1
- How to get rid of decimal places of a number? HOT 1
- Rounding issue HOT 1
- Precision issue with big.js HOT 3
- Support for Comparision operators HOT 2
- Queries for big.js and bignumber.js HOT 2
- typo in license filename HOT 1
- Nullish input of Big constructor results in Error HOT 1
- Can Big.js return Infinity when divide 0? HOT 1
- Add the toSignificantDigits method HOT 1
- Webpack type error angular HOT 1
- Ecma TC39 decimal proposal feedback?
- Cannot divide two Big Numbers
- comperation between two numbers, getting wrong HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from big.js.