Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
Description
Feature or enhancement
Proposal:
I will first post here because I don't want to flood DPO with a controversial thread. I didn't dig much in the issues so it might have already been discussed a bit more in detail elsewhere.
There are some functions inmath.h that we don't export inmath as some are useless for Python or just forgotten. We recently addedisnormal andissubnormal but the following are missing:
scalbn
It's only useful if FLT_RADIX != 2. Python only supports FLT_RADIX = 2 or 16 but I don't know how many systems have FLT_RADIX = 16. So I don't think we need it for now.logb also depends on FLT_RADIX but I think we can ignore it if we don't addscalbn.
DECISION: let's not add it as numpy doesn't have it and it has a confusing name (at least to me).
fdim
This one could be useful to handle possible signed zeros when doing fp artihmetic. Similarly,math currently lacksfmax andfmin which could useful if we support IEC 60559 becausemax(nan, inf) == nan andmax(inf, nan) == inf which is incorrect (in both casesfmax would have returnedinf on such systems).
DECISION: numpy hasfmax andfmin and treat the NaNs correctly, but notfdim. For now, let's not add it.
remquo
This one is useful for implementing
DECISION: numpy doesn't have it and while it could be fine, it's actually really niche.
fpclassify
Now that we have normal and subnormal detection, I suggest we also add this function. This would however require new constants which may or may not be adequate as this would make the module a bit heavier. It was asked in#132908 (comment) but we didn't follow up with that later.
DECISION: I would personally like it but it would more for completeness rather than usefulness, and numpy doesn't have it so I won't push for it.
isunordered
Can be useful to detect if either operand is a NaN. It can save somemath.isnan(x) or math.isnan(y) expression.
DECISION: it is useful but a better named helper in pure Python would do the job.
signbit
Useful for getting the sign of signed zeroes, infinities and NaN.
DECISION: I was wrong in my original statement as Mark pointed out but this one seems the most useful. So I'll work on it tomorrow.
I omitted some functions such asisless as they are directly implemented in Python and I don't think we should do something here. I also omitted rounding functions that depend on the rounding mode as those should be handled byDecimal instead.
Finally, it's unfortunate that we namedmath.gamma instead ofmath.tgamma asmath.gamma could have been confused with Euler-Mascheroni's constant.
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Links to previous discussion of this feature:
No response