romainnorberg / residue Goto Github PK
View Code? Open in Web Editor NEWDivide a float into several parts, with distribution of any remainder
License: MIT License
Divide a float into several parts, with distribution of any remainder
License: MIT License
Hi @romainnorberg,
Sorry for a so soon come back of myself to discuss about a new edge case :
Consider this test :
yield [
100, // value
5, // divide
null, // decimal value
45, // step
[
45,
45,
0,
0,
0,
], // expected result
10, // remainder
];
Of course, it pass perfectly, but maybe it should not... nothing to distribute to 3, 4, and 5 part seems strange in a way...
What do you think ?
According to the set of equation, we can quickly determine if everyone will have something distributed.
The only check to do, it's to check if Divder is greater than Ns. If it is, we can throw an error...Of course, if we consider that this is the expected behaviour.
In the same way, this is a fully valid test :
yield [
100, // value
5, // divide
null, // decimal value
150, // step
[
0,
0,
0,
0,
0,
], // expected result
100, // remainder
];
Hello Romain
I open this issue to discuss two points:
Can a division really be negative? Is there any sense in doing Residue::create(100)->divideBy(-3)? I sincerely ask myself this question and have no idea in either direction.
All methods are public, but I think that many of them don't make sense to be public.
Waiting for your feedback
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.