Search HoldMyTwist

Browse all posts

Episode 42

Duck's Tick-mark Teacups

Duck has 2 measurement cards. The teacup display rounds them to the same value. What should be done with a value half way between the ticks?

Episodes

Computing Basics

    Duck is inside, tuning an imaginary cup volume display that accepts tenths. Robot outside has the precise decimal source cards.
    The number line has 1.24 between 1.20 and 1.30.
    Duck chooses 1.2 the rounded one. The source input remains 1.24, which is four hundredths higher than the rounded number.
    The new exact 1.27 is 70% of the way from 1.20 to 1.30. There is no rounded result displayed yet.
    1.27 gets rounded up to 1.3.
    Robot compares distinct cards of inputs of 1.26 and 1.27. Both of them round to 1.3.
    Duck has 1 rounded number as an output, but 2 possible original inputs.
    The original cards aren't removed. The rounded ones are separate. None of the original are removed or averaged.
    1.25 is just a middle point between 1.20 and 1.30. There is no endpoint chosen yet.
    1.25 halfway, up, arrow picks 1.30 with ties away from zero.
    the arrow picks the more negative -1.30.
    Robot displays two rounding rule cards. Only the story rule (ties away from zero) is in effect. No alternative output displayed.
    There are 3 exact inputs in the hundredths step: 2.344, 2.345, -2.345. No outputs printed yet.
    2.344. You're closer to 2.34 than to 2.35 on the hundredths scale. See, arrow points at 2.34.
    The two middle graphs are the graphs that choose 2.35 for 2.345 and -2.35 for -2.345. The arrows are both pointing away from zero.
    Robot points at step 0.01. Tie rule is unchanged.

    Episode transcript

    A fussy cup display

    Duck is inside, tuning an imaginary cup volume display that accepts tenths. Robot outside has the precise decimal source cards.

    Diagram values: STEP 0.1; EXACT 1.24

    Duck: We round to nearest tenth. It's possible to have different exact numbers which would display the same.

    The number line has 1.24 between 1.20 and 1.30.

    Diagram values: 1.20; 1.24; 1.30

    Robot: We round to nearest tenth. The input is still on this card.

    Duck chooses 1.2 the rounded one. The source input remains 1.24, which is four hundredths higher than the rounded number.

    Diagram values: 1.24 -> 1.2; ERROR -0.04

    Duck: The closest you're getting is 1.2. So that's 4/100ths short.

    The new exact 1.27 is 70% of the way from 1.20 to 1.30. There is no rounded result displayed yet.

    Diagram values: 1.20; 1.27; 1.30; STEP 0.1

    Robot: Where will 1.27 hit with the same step?

    Nearest painted mark

    1.27 gets rounded up to 1.3.

    Diagram values: 1.27 -> 1.3; ERROR +0.03

    Duck: For exact 1.27, the closest tenth is 1.3.

    Robot compares distinct cards of inputs of 1.26 and 1.27. Both of them round to 1.3.

    Diagram values: 1.26 -> 1.3; 1.27 -> 1.3

    Robot: You can get a single rounding value for multiple inputs.

    Duck has 1 rounded number as an output, but 2 possible original inputs.

    Diagram values: 1.26; 1.27; 1.3

    Duck: Then 1.3 does not know what card I started with.

    The original cards aren't removed. The rounded ones are separate. None of the original are removed or averaged.

    Diagram values: ORIGINAL 1.26 / 1.27; ROUNDED 1.3 / 1.3

    Robot: Rounding loses precision.

    The halfway rule

    1.25 is just a middle point between 1.20 and 1.30. There is no endpoint chosen yet.

    Diagram values: 1.20; 1.25; 1.30

    Duck: 1.25 is equidistant between 1.2 and 1.3. It's 0.05 in both directions.

    1.25 halfway, up, arrow picks 1.30 with ties away from zero.

    Diagram values: TIES AWAY FROM ZERO; 1.25 -> 1.3

    Robot: I would use the neighbour that is further from zero for exact ties.

    the arrow picks the more negative -1.30.

    Diagram values: -1.30; -1.25; -1.20; -1.25 -> -1.3

    Duck: So the ties-away-from-zero says -1.3

    Robot displays two rounding rule cards. Only the story rule (ties away from zero) is in effect. No alternative output displayed.

    Diagram values: ACTIVE: TIES AWAY FROM ZERO

    Robot: Other systems might be using some other tie rule.

    Another shelf of cups

    There are 3 exact inputs in the hundredths step: 2.344, 2.345, -2.345. No outputs printed yet.

    Diagram values: STEP 0.01; 2.344; 2.345; -2.345; TIES AWAY FROM ZERO

    Duck: Please round this set of cards

    2.344. You're closer to 2.34 than to 2.35 on the hundredths scale. See, arrow points at 2.34.

    Diagram values: 2.344 -> 2.34

    Robot: 2.344 is closer to 2.34 than 2.35.

    The two middle graphs are the graphs that choose 2.35 for 2.345 and -2.35 for -2.345. The arrows are both pointing away from zero.

    Diagram values: 2.345 -> 2.35; -2.345 -> -2.35

    Duck: Both away from zero.

    Robot points at step 0.01. Tie rule is unchanged.

    Diagram values: STEP 0.01; TIES AWAY FROM ZERO

    Robot: We save the source values.

    The lesson

    If you're rounding from a precise decimal to step 0.1, it means the nearest tenth. To step 0.01 it means the nearest hundredth. For our rule, exact halfway ties get pushed away from zero. Many exact values could produce the same rounded output. As a result, that rounded output isn't going to pinpoint the exact input. We save the source values.

    Try it

    Use step 0.01 and exact ties away from zero. Round exact decimals 3.454, 3.455, -3.455 separately.

    Answer

    3.454: to 3.45 (nearest hundredth) Exact ties (3.455, -3.455): away from 0 (to 3.46, -3.46)

    Sources

    Python decimal documentation: rounding modes (opens in a new tab)