Skip to content
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

RFC: Nim Math functions #92

Open
jlp765 opened this issue Jan 19, 2016 · 5 comments
Open

RFC: Nim Math functions #92

jlp765 opened this issue Jan 19, 2016 · 5 comments

Comments

@jlp765
Copy link

jlp765 commented Jan 19, 2016

Stock-take of Math functions

This is a comparison of math functions, with the aim of helping to identify if any functions are missing that may need to be added, etc. (in preparation for Nim V1.0)

Don't assume I correctly identified the Nim math functions (I may have missed some, or are available in other Nimble packages).

Function Nim POSIX old ISO ISO C99 Microsoft Notes
acos Y (arccos) Y Y Y Y
acosh Y (arccosh)\ Y N Y N
asin Y (arcsin) Y Y Y Y
asinh Y (arcsinh) Y N Y N
atan Y (arctan) Y Y Y Y
atan2 Y (arctan2) Y Y Y Y
atanh Y (arctanh) Y N Y N
cbrt Y Y N Y N
ceil Y Y Y Y Y
copysign N Y N Y Y _copysign
cos Y Y Y Y Y
cosh Y Y Y Y Y
erf Y Y N Y N
erfc Y Y N Y N
exp Y Y Y Y Y
exp2 N Y N Y N
expm1 N Y N Y N
fabs Y (abs) Y Y Y Y
fdim N Y N Y N
floor Y Y Y Y Y
fma N Y N Y N
fmax Y (max) Y N Y N
fmin Y (min) Y N Y N
fmod Y (mod) Y Y Y Y
fpclassify Y (classify) Y N Y Y _fpclass
frexp Y Y Y Y Y
hypot Y Y N Y Y _hypot
ilogb N Y N Y N
isfinite N Y N Y N
isgreater N Y N Y N
isgreaterequal N Y N Y N
isinf N Y N Y N
isless N Y N Y N
islessequal N Y N Y N
islessgreater N Y N Y N
isnan N Y N Y Y _isnan
isnormal N Y N Y N
isunordered N Y N Y N
j0 N Y N N Y _j0
j1 N Y N N Y _j1
jn N Y N N Y _jn
ldexp N Y Y Y Y
lgamma Y Y N Y N
llrint Y (round?) Y N Y N
llround N Y N Y N
log Y (ln) Y Y Y Y
log10 log10 Y Y Y Y
log1p Y N Y N
log2 Y Y N Y N
logb N Y N Y Y _logb
lrint Y (round) Y N Y N
lround N Y N Y N
modf Y (mod) Y Y Y Y
nan N (?) Y N Y N
nearbyint N Y N Y N
nextafter N Y N Y Y _nextafter
nexttoward N N N Y N
pow Y Y Y Y Y
remainder N (mod?) Y N Y N
remquo N Y N Y N
rint Y (round) Y N Y N
round N Y N Y N
scalbln N Y N Y N
scalbn N N N Y N
signbit N Y N Y N
sin Y Y Y Y Y
sinh Y Y Y Y Y
sqrt Y Y Y Y Y
tan Y Y Y Y Y
tanh Y Y Y Y Y
tgamma Y Y N Y N
trunc Y Y N Y N
y0 N Y N N Y _y0
y1 N Y N N Y _y1
yn N Y N N Y _yn

(the base table came from http://www.johndcook.com/blog/math_h/ )

links

@jlp765 jlp765 changed the title Nim Math functions RFC: Nim Math functions Jan 19, 2016
@dom96
Copy link
Contributor

dom96 commented Apr 4, 2016

I think it makes sense to include everything that is in ISO 99. Please create a PR to do so if you've got some time.

@abudden
Copy link

abudden commented Jun 1, 2016

An equivalent to modf is now included in 46a2993917edd73fe55623a06999f4811067a754 (although it's called splitDecimal and returns the values as a tuple rather than passing a reference to an argument).

@narimiran narimiran transferred this issue from nim-lang/Nim Jan 13, 2019
@timotheecour
Copy link
Member

timotheecour commented Nov 29, 2020

we should have a std/cmath.nim that is a pure low-level wrapper around importc procs.

Then std/math can import it but also work cross-backend with high-level portable wrappers that work in c,cpp,js,vm,nimscript backends.

EDIT: refs nim-lang/Nim#16179 (comment)

@ringabout

This comment was marked as outdated.

@timotheecour
Copy link
Member

timotheecour commented Nov 29, 2020

  • not everything in this list is equally valuable, we should focus on most common first (subjective, yes).

lrint | Y (round)

  • we actually don't have lrint and I wish we did; round is different.
    maybe something like:
type RoundMode = enum rTowardsZero, ...
proc roundTo(x: SomeFloat, T: typedesc[SomeNumber], mode: static RoundMode): T
# or:
proc roundToInt(x: SomeFloat, mode: static RoundMode): int

which would map to one of the many lrint, lrintl, llrintl, round...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants