round in 2.6 and 2.7

Mark Dickinson dickinsm at gmail.com
Wed Dec 29 05:52:52 EST 2010


On Dec 28, 9:47 pm, "Martin v. Loewis" <mar... at v.loewis.de> wrote:
> >> "Float-to-string and string-to-float conversions are correctly rounded.
> >> The round() function is also now correctly rounded."
>
> >> Not sure that this is correct English; I think it means that the
> >> round() function is now correct.
>
> > Well, the correct result of the example the OP gave would be 9.9
> > exactly.  But since 9.9 isn't exactly representable as a Python float,
> > we necessarily get an approximation.  The language above is intended
> > to convey that it's the 'correctly rounded' approximation
>
> I see. Shouldn't it say then "The round() function
> gives/produces/returns correctly rounded results now", instead of saying
> that
> the round function *is* correctly rounded? ISTM that the round
> function cannot be rounded (correctly or not):
>
> py> round(round)
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> TypeError: a float is required
>
> But then, I'm not a native speaker (of English).

I dare say that you're just as much a native speaker as anyone else
when it comes to the language of floating-point arithmetic.  Not sure
English comes into it that much. :-)

Sure, I agree it's probably a slight abuse of language to refer to a
function as 'correctly rounded', but I think it's a fairly standard
abuse. From the two nearest references to hand: IEEE 754-2008 has a
whole section entitled 'Recommended correctly rounded functions' (nit:
shouldn't there be a hyphen in that title?), and persists in referring
to 'correctly rounded' conversions.  The more formal uses in that
document do indeed refer to single values, though. ("A conforming
function shall return results correctly rounded ...") The 'Handbook of
Floating-Point Arithmetic' by Muller et. al. gives a definition of a
correctly rounded function in section 2.2.  "When the exact result of
a function is rounded according to a given rounding mode ..., one says
that the function is *correctly rounded*."

It's not so dissimilar from other mathematical abuses, like describing
a real-valued function as 'positive', when what you actually mean is
that all its values are positive.

It's also slightly unsettling usage for me, not least because the
statement 'f is correctly rounded' for a floating-point function f is
really a statement about *two* functions:  namely, f (a function from
floating-point numbers to floating-point numbers) and the true
mathematical function that it's based on;  the identity of the
underlying mathematical function is left implicit.

--
Mark



More information about the Python-list mailing list