Comments (4)
There's getUnscaledValue() which probably fits your needs (this returns a BigInteger though, so you would need to cast it to string).
Ah yeah that works 👍 I'm sure I saw it but it didn't immediately return a string so I just read past it I think.
feels asymmetrical to me
Can you please expand on this?
What I mean is multipliedBy
is past tense & has the By
which doesn't match with plus
which is present tense (I guess?) and has no By
.
I think times()
would align better. Or going the other way, incrementedBy
(or something like that) instead of plus
... but that sounds crazy 😅
I dunno, it just feels kinda long having a 12 character method name when an equivalent 5 character one could exist. Both are a lot more verbose than *
(if we had operator overloading... we can still dream).
Anyway I think we can close this because I think we agree __debugInfo
isn't needed. But 🤷♂️ I think there's still some room for UX improvements for the method names probably, not that important though.
from math.
Hi @francislavoie, I can't see any negative side effects to adding __debugInfo
, apart from the fact that it may only be useful for Symfony, as I think that PHP itself would always output private properties in var_dump()
.
Also, if I run it in isolation, I can see that Symfony's dump()
also dumps the private properties by default:
Do you know the rules used by VarDumper to decide whether or not to display properties? Are we sure that adding __debugInfo()
will always force it to output them?
from math.
Ah, right. It's cause psysh
turns on some flags to hide protected & private properties. They use Caster::filter($a, Caster::EXCLUDE_PROTECTED | Caster::EXCLUDE_PRIVATE)
. They appear if they're in debugInfo though because I think that effectively promotes it to public, I think?
I have another workaround for now though, VarDumper has configurable "Casters" which are callbacks which return a map of properties. I decided to do this for our own use for now:
/**
* @param BigDecimal $decimal
* @return array
*/
public static function castBigDecimal($decimal)
{
return [
Caster::PREFIX_VIRTUAL.'string' => (string) $decimal,
];
}
Ultimately the value/scale are not that relevant for our own use so I decided to use the string cast which has less mental overhead to read at a glance.
I did notice that pretty much the only way to get the value&scale is to call ->serialize()
which is marked @internal
so it felt dirty. Maybe there should be a ->getValue()
to match ->getScale()
?
(Totally off-topic, I was instinctually looking for ->times()
and ->add()
but instead there's ->multipliedBy()
and ->plus()
, feels asymmetrical to me 🤷♂️ would be cool if those aliases existed I think)
from math.
Ultimately the value/scale are not that relevant for our own use so I decided to use the string cast which has less mental overhead to read at a glance.
For VarDumping, I agree that a string representation is a better fit as it's meant to be human readable.
I have another workaround for now though, VarDumper has configurable "Casters" which are callbacks which return a map of properties
I think this is the way to go, this is problably something that you want to configure in your application, outside of brick/math!
Maybe there should be a
->getValue()
to match->getScale()
?
There's getUnscaledValue()
which probably fits your needs (this returns a BigInteger
though, so you would need to cast it to string
).
(Totally off-topic, I was instinctually looking for
->times()
and->add()
but instead there's->multipliedBy()
and->plus()
, feels asymmetrical to me 🤷♂️ would be cool if those aliases existed I think)
I'm a bit against having multiple methods that do the same thing, I like that 2 codebases (or worse, 2 parts of the same codebase) can't use different method names for the same thing, for the sake of consistency.
Especially, I'm against add()
as, IMO, it might imply mutability, whereas plus()
sounds more logical to me for something that returns a new value and leaves the original value unchanged.
feels asymmetrical to me
Can you please expand on this?
from math.
Related Issues (20)
- brick/math method for gmp_random_range HOT 4
- brick/math method for gmp_invert HOT 8
- The given value ".1200" does not represent a valid number. HOT 2
- Add a changelog HOT 3
- 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
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.