(original) (raw)
No, the whole point of \_\_index\_\_ is that it refuses \*all\* floats -- otherwise people will do approximate computations that for their simple test inputs give whole numbers, use them as sequence indices, and then find their code broken only when the computation incurs some floating point approximation. OTOH, is\_integer() specifically asks whether a given real value is a whole number so you can cast it to int() without rounding, etc.
On Tue, Mar 20, 2018 at 5:32 PM, Chris Barker <chris.barker@noaa.gov> wrote:
Anyway, it seems like \_\_index\_\_() should play a role here somehow... isn't that how you ask an object for the integer version of itself?It seems .as\_integer\_ratio() has been resolved.what about the original .is\_integer() request? (Or did I miss that somehow?)Could float et al. add an \_\_index\_\_ method that would return a ValueError if the value was not an integer?Of course, as pointed out earlier in this thread, an "exact" integer is probably not what you want with a float anyway....-CHBOn Tue, Mar 13, 2018 at 10:29 PM, Tim Peters <tim.peters@gmail.com> wrote:\[Tim\]
>> An obvious way to extend it is for Fraction() to look for a special
\>> method too, say "\_as\_integer\_ratio()".
\[Greg Ewing\]
\> Why not \_\_as\_integer\_ratio\_\_?
Because. at this point, that would be beating a dead horse ;-)
\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: https://mail.python.org/mailman/options/python-dev/chris. barker%40noaa.gov
--
Christopher Barker, Ph.D.
Oceanographer
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chris.Barker@noaa.gov
\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: https://mail.python.org/mailman/options/python-dev/ guido%40python.org
--
--Guido van Rossum (python.org/\~guido)