Reply To: Converting fractions to decimals

Advert

Reply To: Converting fractions to decimals

Home Forums Hints And Tips for model engineers Converting fractions to decimals Reply To: Converting fractions to decimals

#558782
SillyOldDuffer
Moderator
    @sillyoldduffer
    Posted by SillyOldDuffer on 17/08/2021 17:26:40:

    Posted by Michael Gilligan on 17/08/2021 13:49:11:

    Posted by SillyOldDuffer on 17/08/2021 12:03:49:

    […]

    All fraction calculators suffer to some degree from this inaccuracy, though the more sophisticated versions do far better than simple minded digital calipers. Michael's example is close: his calculator (and Nick's) both give 1¹¹⁄₁₆ x 25.4 = ³⁴²⁹⁄₈₀. So does mine. However, the real answer is ⁹⁶⁵¹⁷⁷⁶⁹⁵¹⁴⁰⁸³⁹³⁷⁄₂₂₅₁₇₉₉₈₁₃₆₈₅₂₄₈. Don't panic, ³⁴²⁹⁄₈₀ is an excellent result, the error being only -²⁷⁄₁₁₂₅₈₉₉₉₀₆₈₄₂₆₂₄₀.

    Highlights a serious problem with fractions because the level of inaccuracy of each calculation depends on the individual ratio and on the number of display digits available. […]

    .

    dont know

    You must try harder, Dave

    The fractional answer is correct

    Sadly it's true, I've cocked up AGAIN!

    Sorry,

    Dave

    PS Nurse says bed with no supper tonight…

    embarrassed

    Feeling a little happier with my foolish self this morning because my mistake was trusting a calculator; ironic because my post was about distrusting calculators doing fractions.

    I used Python because it supports Fractions and Decimals as well as floating point. Floating point arithmetic is super fast because the numbers are in binary, but this causes conversion errors. 25.4 is actually stored as 0.25399999999999998579×100, which can cause trouble in long complicated calculations.

    Decimal numbers are exact – 2.4 really is 2.4 but they are slow.

    In Python, I typed:

    fd = 1 + Fraction(11,16)
    fd = fd * Fraction(Decimal(25.4))
    print( fd, fd.limit_denominator() )

    which gives the slightly wrong answer 96517769514083937/2251799813685248, which was approximated by limit_denominator() to 3429/80

    Doing the same sum in fractions throughout gives the right answer:

    ff = 1 + Fraction(11,16)
    ff = ff * ( 25 + Fraction(4,10))
    print( ff, ff.limit_denominator() )

    3429/80 3429/80

    So my blunder was caused by whatever method Python uses to convert Decimal(25.4) into a fraction.

    Although I dislike fractions intensely in engineering drawings, they are perfect for gear ratios: change gears and threads. In that context, Python's limit_denominator() function is good for finding approximations, for example:

    Fraction(math.pi).limit_denominator(10) = 22/7
    Fraction(math.pi).limit_denominator(100) = 311/99
    Fraction(math.pi).limit_denominator(1000) = 355/113

    The various methods discussed in this thread are just tools. Tug's calculator may be good choice for him but other tools are available, and could be exactly the right tool for others. Calculators aren't the ultimate calculating aid!

    Spreadsheets are calculators on steroids, but harder to learn. Programming languages even tougher but can do almost any calculation. As I've demonstrated though, just like physical tools, the operator has to choose and use them correctly. Banging screws in with a hammer is rarely a good idea,

    Dave

    Advert

    Advert

    Latest Replies

    Viewing 25 topics - 1 through 25 (of 25 total)
    Viewing 25 topics - 1 through 25 (of 25 total)

    View full reply list.

    Advert

    Newsletter Sign-up