Giter Site home page Giter Site logo

Comments (1)

BenMorel avatar BenMorel commented on August 28, 2024 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 divisor
  • BigInteger::dividedBy() needs a divisor and a rounding mode
  • BigDecimal::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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.