Comments (1)
Hi, this could have been BigNumber
, which already knows how to handle comparison between types, and cross-type additions (see BigNumber::sum()
.
That being said, plus()
, minus()
etc. are already defined on subclasses, and they return an instance of the subclass. We cannot move the implementation to BigNumber
, and make each operation return a potentially different type than the type you call the method on, without drastically changing the behaviour of the library (for the worse, IMO).
So this would need to be a new class indeed. But it comes with its own challenges: only addition / subtraction / multiplication could be implemented on this class, as the signature of dividedBy()
in each number class is different:
BigRational::dividedBy()
only needs a divisorBigInteger::dividedBy()
needs a divisor and a rounding modeBigDecimal::dividedBy()
needs a divisor, a scale and a rounding mode
I'm wondering, if you're re-writing a TS library to PHP, are you dealing with number
types? Or with arbitrary precision?
In the former case, the equivalent would just be using float
in PHP. AFAIK, Both PHP's float
and JS' number
are IEEE 754 double-precision numbers, so you should observe the same behaviour (and the same gotchas, obviously).
from math.
Related Issues (20)
- Rounding error on exactlyDividedBy() HOT 2
- Fatal error: Maximum execution time of 30 seconds exceeded HOT 2
- RFC: add `getPrecision` method. HOT 11
- Issue with dividedBy and MultipliedBy? HOT 3
- Feature Request: Implement lisachenko/z-engine HOT 1
- BigComplex HOT 2
- How to accept any scale without rounding HOT 1
- Accept hexadecimal input HOT 1
- Rounding is necessary to represent the result of the operation at this scale. HOT 2
- [0.10.0] behavior change HOT 1
- Please support php8.1 HOT 1
- Implements the Serializable interface, which is deprecated HOT 1
- `gmp_export` equivalent HOT 6
- Rounding bug, or am I just dumb? HOT 4
- Output a BigRational in decimal form with period
- Implement `__debugInfo` magic method HOT 4
- BigDecimal's scale should be zero when all fractional digits are zero HOT 2
- MathException extends Exception
- When installing math i got this massage 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 math.