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

Make std.math.fmax() and .fmin() variadic. Add explicit NaN handling. #4346

Closed
wants to merge 1 commit into from

Conversation

tsbockman
Copy link
Contributor

@tsbockman tsbockman commented May 23, 2016

No description provided.


if (mixin(`m4 ` ~ op ~ ` ret`))
ret = m4;
else if (m4.isNaN)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be the first comparison?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No.

@9il
Copy link
Member

9il commented May 23, 2016

fmax and fmin should have 2 args and be simple math functions like in C. All additional logic can be located in max and min

@9il
Copy link
Member

9il commented May 23, 2016

my suggestion was to use fmax and fmin in max and min.

@9il
Copy link
Member

9il commented May 23, 2016

fmin and fmax should be compiler intrinsics.

@9il 9il closed this May 23, 2016
@9il
Copy link
Member

9il commented May 23, 2016

@tsbockman
Copy link
Contributor Author

fmin and fmax should be compiler intrinsics.

Shouldn't they be in core.math then?

@9il
Copy link
Member

9il commented May 23, 2016

Shouldn't they be in core.math then?

I don't know.

See std.math in LDC Phobos
https://github.com/ldc-developers/phobos/blob/release-0.17.1/std/math.d#L653

The best option for math functions is to be templates (so they can be inlined) and support all FP types.

@tsbockman
Copy link
Contributor Author

The description of core.math says "Builtin mathematical intrinsics":
https://dlang.org/phobos/core_math.html

@9il
Copy link
Member

9il commented May 23, 2016

The description of core.math says "Builtin mathematical intrinsics":
https://dlang.org/phobos/core_math.html

But this is just declarations.

@tsbockman
Copy link
Contributor Author

tsbockman commented May 23, 2016

But this is just declarations.

It is analogous to core.checkedint and core.bitop, which also contain software fallback implementations.

@9il
Copy link
Member

9il commented May 23, 2016

But this is just declarations.
It is analogous to core.checkedint and core.bitop, which also contain software fallback implementations.

This is not really important.

Functions in core.math and std.math are deprecated:

  1. They are real centric: this slowdown execution on modern x86_64 CPUs
  2. They are not templates, so they are not inlined: this slowdown execution on modern x86_64 CPUs too

The good std.math update should allow to use all math functions from LLVM list http://llvm.org/docs/LangRef.html#standard-c-library-intrinsics.

@tsbockman
Copy link
Contributor Author

They are real centric: this slowdown execution on modern x86_64 CPUs

This can be fixed. There's nothing stopping us from adding double and float overloads to core.math.

They are not templates, so they are not inlined: this slowdown execution on modern x86_64 CPUs too

core.math is for intrinsics which are not normal functions, but are effectively always inlined (even across modules). They are implemented in the compiler backend, I believe.
https://en.wikipedia.org/wiki/Intrinsic_function

@tsbockman tsbockman deleted the unorder_NaN branch May 23, 2016 11:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants