Michael Hudson schrieb: >> 1. it is possible to determine whether the value is "special" in >> constant time, and also fetch the singleton value in constant >> time for ints; the same isn't possible for floats. > > I don't think you mean "constant time" here do you?
Right; I really wondered whether the code was dependent or independent of the number of special-case numbers. > I think most of > the code posted so far has been constant time, at least in terms of > instruction count, though some might indeed be fairly slow on some > processors -- conversion from double to integer on the PowerPC > involves a trip off to memory for example. Kristian's code testing only for integers in a range would be of that kind. Code that tests for a list of literals determined at compile time typically needs time "linear" with the number of special-cased constants (of course, as that there is a fixed number of constants, this is O(1)). >> 2. it may be that there is a loss of precision in reusing an existing >> value (although I'm not certain that this could really happen). >> For example, could it be that two values compare successful in >> ==, yet are different values? I know this can't happen for >> integers, so I feel much more comfortable with that cache. > > I think the only case is that the two zeros compare equal, which is > unfortunate given that it's the most compelling value to cache... Thanks for pointing that out. I can believe this is the only case in IEEE-754; I also wonder whether alternative implementations could cause problems (although I don't really worry too much about VMS). Regards, Martin _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com