New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
float(0.0) singleton #48274
Comments
Here is a patch to make PyFloat_FromDouble(0.0) always return the same My own motivation is that the patch reduces memory by several megabytes |
Will it correctly distinguish between +0.0 and -0.0? |
No it won't distinguish between +0.0 and -0.0 in its present form,
because these two have the same value according to the C equality
operator. This should be easy to adjust, eg we could exclude -0.0 by
changing the comparison
if (fval == 0.0)
into
static double positive_zero = 0.0;
...
if (!memcmp(&fval, &positive_zero, sizeof(double))) |
We need maybe more hardcoded floats. I mean a "cache" of current def cache_float(value):
return abs(value) in (0.0, 1.0, 2.0)
def create_float(value):
try:
return cache[value]
except KeyError:
obj = float(value)
if cache_value(value):
cache[value] = obj
return obj Since some (most?) programs don't use float, the cache is created on Since the goal is speed, only a benchmark can answer to my question |
Please use copysign(1.0, fval) == 1.0 instead of your memcpy trick. It's I've to check with Guido and Barry if we can get the optimization into |
I question whether this should be done at all. Making the creation of a Tim, any insights? |
I have 3 comments for future readers who might want to reopen.
|
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: