Menu

#5790 Rational conversion clean-up

Fixed
Dan Eble
Enhancement
2020-02-29
2020-02-25
Dan Eble
No

This review squashes these commits that mainly clean up initialization
and conversion of Rationals, though there are some minor bug fixes.

For most of the unit tests which are disabled here, I have fixes that
I am holding back for the sake of simplifying this review.

1: create unit tests

2: remove unused infinity_rat

3: use default copy-construction and assignment

4: disambiguate integer conversions
and fix sign when initialized by unsigned integer

5: disable implicit conversion to bool

6: discard r.to_double () in favor of static_cast<double> (r)
This helps developers avoid question-raising statements like this:
Real x = r.to_double ();
and encourages statements like this:
auto x = static_cast<real> (r);</real></double>

7: disable implicit conversion to double
This helps emphasize places where exactness might be lost.

8: to_int () becomes trunc_int ()
and returns I64 like num () and den ().

https://codereview.appspot.com/573570043

Discussion

  • Anonymous

    Anonymous - 2020-02-25

    Passes make, make check and a full make doc.

     
  • Anonymous

    Anonymous - 2020-02-25
    • Description has changed:

    Diff:

    
    
    • Needs: -->
    • Patch: new --> review
     
  • Anonymous

    Anonymous - 2020-02-26
    • Patch: review --> countdown
     
  • Anonymous

    Anonymous - 2020-02-26

    Patch on countdown for Feb 28th

     
  • Anonymous

    Anonymous - 2020-02-28
    • Patch: countdown --> push
     
  • Anonymous

    Anonymous - 2020-02-28

    Patch counted down - please push.

     
  • Dan Eble

    Dan Eble - 2020-02-29
    • labels: --> Fixed_2_21_0
    • status: Started --> Fixed
    • Patch: push -->
     
  • Dan Eble

    Dan Eble - 2020-02-29
    commit 1a061b0d2b7e3b50c8f2846008882325dfe1fec8
    Author: Dan Eble <nine.fierce.ballads@gmail.com>
    Date:   Sat Feb 22 22:10:33 2020 -0500
    
        Issue 5790/8: Rational: to_int () becomes trunc_int ()
    
        ... and returns I64 like num () and den ().
    
    commit f0e68ea3a9c8db6d7b81a3f7fd797804b26c9cbf
    Author: Dan Eble <nine.fierce.ballads@gmail.com>
    Date:   Sat Feb 22 12:53:31 2020 -0500
    
        Issue 5790/7: Rational: disable implicit conversion to double
    
        This helps emphasize places where exactness might be lost.
    
    commit 95bf2fde4b95969875dd2cfe96b4424175ca3885
    Author: Dan Eble <nine.fierce.ballads@gmail.com>
    Date:   Sat Feb 22 12:53:31 2020 -0500
    
        Issue 5790/6: Rational: r.to_double () becomes static_cast<double> (r)
    
        This helps developers avoid question-raising statements like this:
    
            Real x = r.to_double ();
    
        and encourages statements like this:
    
            auto x = static_cast<Real> (r);
    
    commit 7cfd8a44caa6d7e1de02b0c8e3ffa501fb9f4bce
    Author: Dan Eble <nine.fierce.ballads@gmail.com>
    Date:   Sat Feb 22 12:53:31 2020 -0500
    
        Issue 5790/5: Rational: disable implicit conversion to bool
    
    commit b8028efa6daf9e2be3617bf6ff9dd8b13d303bb0
    Author: Dan Eble <nine.fierce.ballads@gmail.com>
    Date:   Sat Feb 22 22:09:42 2020 -0500
    
        Issue 5790/4: Rational: disambiguate integer conversions
    
        ... and fix sign when initialized by unsigned integer
    
    commit 532e06e784035bf3fdbedb590cf4e6fe070178e2
    Author: Dan Eble <nine.fierce.ballads@gmail.com>
    Date:   Sat Feb 22 09:17:12 2020 -0500
    
        Issue 5790/3: Rational: use default copy-construction and assignment
    
    commit 2a7c4146cac93710d02106c8f729b8e7333e656d
    Author: Dan Eble <nine.fierce.ballads@gmail.com>
    Date:   Sat Feb 22 12:45:18 2020 -0500
    
        Issue 5790/2: Rational: remove unused infinity_rat
    
    commit 8466b6dbc630d1862f193d081f6de7ae9a4a1d3d
    Author: Dan Eble <nine.fierce.ballads@gmail.com>
    Date:   Fri Feb 21 18:26:04 2020 -0500
    
        Issue 5790/1: Rational: create unit tests