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 in math.h that we don't export in math as some are useless for Python or just forgotten. We recently added isnormal and issubnormal but the following are missing:
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 add scalbn.
DECISION: let's not add it as numpy doesn't have it and it has a confusing name (at least to me).
This one could be useful to handle possible signed zeros when doing fp artihmetic. Similarly, math currently lacks fmax and fmin which could useful if we support IEC 60559 because max(nan, inf) == nan and max(inf, nan) == inf which is incorrect (in both cases fmax would have returned inf on such systems).
DECISION: numpy has fmax and fmin and treat the NaNs correctly, but not fdim. For now, let's not add it.
This one is useful for implementing $t$-periodic functions for $t$ exactly representable as an fp-value. I don't know if users are expected to actually work in Python for such functions, but I think we can expose it.
DECISION: numpy doesn't have it and while it could be fine, it's actually really niche.
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.
Can be useful to detect if either operand is a NaN. It can save some math.isnan(x) or math.isnan(y) expression.
DECISION: it is useful but a better named helper in pure Python would do the job.
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 as isless 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 by Decimal instead.
Finally, it's unfortunate that we named math.gamma instead of math.tgamma as math.gamma could have been confused with Euler-Mascheroni's constant.
cc @skirpichev @tim-one
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
Linked PRs
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 in
math.hthat we don't export inmathas some are useless for Python or just forgotten. We recently addedisnormalandissubnormalbut the following are missing:scalbnIt'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.
logbalso 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).
fdimThis one could be useful to handle possible signed zeros when doing fp artihmetic. Similarly,
mathcurrently lacksfmaxandfminwhich could useful if we support IEC 60559 becausemax(nan, inf) == nanandmax(inf, nan) == infwhich is incorrect (in both casesfmaxwould have returnedinfon such systems).DECISION: numpy has
fmaxandfminand treat the NaNs correctly, but notfdim. For now, let's not add it.remquoThis one is useful for implementing$t$ -periodic functions for $t$ exactly representable as an fp-value. I don't know if users are expected to actually work in Python for such functions, but I think we can expose it.
DECISION: numpy doesn't have it and while it could be fine, it's actually really niche.
fpclassifyNow 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.
isunorderedCan be useful to detect if either operand is a NaN. It can save some
math.isnan(x) or math.isnan(y)expression.DECISION: it is useful but a better named helper in pure Python would do the job.
signbitUseful 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 as
islessas 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 byDecimalinstead.Finally, it's unfortunate that we named
math.gammainstead ofmath.tgammaasmath.gammacould have been confused with Euler-Mascheroni's constant.cc @skirpichev @tim-one
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
Linked PRs
math.signbit#135877math.fmaxandmath.fmin#135888