Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to store Fraction in original format #22

Open
tomhv opened this issue Dec 21, 2016 · 3 comments
Open

Add ability to store Fraction in original format #22

tomhv opened this issue Dec 21, 2016 · 3 comments

Comments

@tomhv
Copy link
Collaborator

tomhv commented Dec 21, 2016

Currently functionality

echo new Fraction(2,4); // 1/2

Proposed functionality

echo new Fraction(2,4); // 2/4

Open questions

  1. Would simplify() modify the current object or return a new, simplified fraction?

    a. Modify current object:

    $twoQuarters = new Fraction(2, 4);
    echo $twoQuarters; // 2/4
    $twoQuarters->simplfy();
    echo $twoQuarters; // 1/2

    b. Return new Fraction

    $twoQuarters = new Fraction(2, 4);
    echo $twoQuarters; // 2/4
    $oneHalf = $twoQuarters->simplfy();
    echo $twoQuarters; // 2/4
    echo $oneHalf; // 2/4
  2. Should we just get rid of simplify() in the constructor completely?

    public function __construct($numerator, $denominator = 1)
    {
        // ...
        // $this->simplify();
    }
  3. How should we cope with 1 3/4? Should we introduce a whole number part? This would allow us to distinguish between 7/4 and 1 3/4.

@jazzdan
Copy link

jazzdan commented Dec 21, 2016

Would simplify() modify the current object or return a new, simplified fraction?

Hm, I would accept that simplifying automatically should be default. What if we just kept a reference internally to the originally entered fraction?

Otherwise I would be in favor of returning a new Fraction object since I'm a sucker for functional programming. :)

Should we just get rid of simplify() in the constructor completely?

I think that's probably the most straightforward way to implement this.

How should we cope with 1 3/4? Should we introduce a whole number part? This would allow us to distinguish between 7/4 and 1 3/4.

Yeah that's a good question. The dumbest solution is to just keep a reference to the originally referenced string, similarly to how I proposed handling the originally entered numerator and denominator but I don't think that's the best solution.

@tomhv
Copy link
Collaborator Author

tomhv commented Jan 4, 2017

Hey @jazzdan, sorry for the radio silence. Things pretty much shut down over the Christmas hols. Hope to get back onto this in the next few days.

@jazzdan
Copy link

jazzdan commented Jan 4, 2017

No worries, same here. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants