Re: is int(round(val)) safe?

From: Peter Hansen (peter_at_engcorp.com)
Date: 11/22/04


Date: Mon, 22 Nov 2004 16:46:02 -0500

Steven Bethard wrote:
> Peter Hansen wrote:
>> Since round() returns an integer
>
> Just to clarify in case anyone else misreads this, I belive the intent
> here was to say that round(f) -- that is, round with only a single
> argument -- returns a floating point number with no fractional component
> after the decimal point. The result is still a float, not an int though:
>
> >>> round(3.14159265359)
> 3.0
> >>> round(3.14159265359, 2)
> 3.1400000000000001
>
> I think the intent was clear from the rest of the post, but I figured it
> wouldn't hurt to clarify this for any newbies who misread it like I did.

All true.

I wonder if it would be appropriate to say something along
the lines of '''round() returns an integer, but not an "int".'''

Obviously the mathematicians will have something to say about
this. In computers, 1.0 may not be an integer data type, but
I think in math it's still considered an integer. I am most
definitely not going to claim authority in this area, however,
since as an engineer I consider 1.0 and 1 merely "equal to a
first approximation". <wink>

-Peter



Relevant Pages

  • Re: is int(round(val)) safe?
    ... Just to clarify in case anyone else misreads this, ... here was to say that round(f) -- that is, ... I think the intent was clear from the rest of the post, ... wouldn't hurt to clarify this for any newbies who misread it like I did. ...
    (comp.lang.python)
  • Re: matlab fscanf
    ... way in the future -- it would be best to report only the exact ... it's possible the intent to clarify will ... simply obfuscate. ...
    (comp.soft-sys.matlab)
  • Re: When Overloading the Plus Operator, What are Valid Arguments Types?
    ... enthusiastically to pin down the root cause. ... family to clarify the intent. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Binoculars?
    ... To clarify, one who 'religously' engages in using slightly mis-spoken ... Generally with the intent of producing an ... amused reaction. ...
    (rec.outdoors.rv-travel)

Loading