It is arbitrary, but not chosen by us ;) we can blame someone else.

Sent from my Phone

On 2013-07-17, at 15:40, Erik Bray <notifications@github.com> wrote:

In astropy/units/format/utils.py:

> @@ -107,6 +108,23 @@ def decompose_to_known_units(unit, func):
>          return unit
>
>
> +def format_power(power):
> +    """
> +    Converts a value for a power (which may be floating point or a
> +    `fractions.Fraction` object), into a string either looking like
> +    an integer or a fraction.
> +    """
> +    if not isinstance(power, Fraction):
> +        if power % 1.0 != 0.0:
> +            frac = Fraction.from_float(power)
> +            power = frac.limit_denominator(10)

Yeah, an example that's a bit odd but not unthinkable might be, say, 7/3:

>>> Fraction.from_float(7.0 / 3.0)
Fraction(5254199565265579, 2251799813685248)

but

>>> fractions.Fraction.from_float(7.0 / 3.0).limit_denominator()
Fraction(7, 3)

is good enough. Reason being that with many floating point numbers with
infinitely repeating digits (2.33333333~) the round off is in a very small
decimal place, which leads to very large denominators. 1000000 is still
sort of arbitrary but it seems well within reason to me for most small
rational numbers.

—
Reply to this email directly or view it on
GitHub<https://github.com/astropy/astropy/pull/1232/files#r5251875>
.