Skip to content

Comments

Add public examples to many functions to std.math#6409

Merged
JackStouffer merged 1 commit intodlang:masterfrom
JackStouffer:math-examples3
Apr 3, 2018
Merged

Add public examples to many functions to std.math#6409
JackStouffer merged 1 commit intodlang:masterfrom
JackStouffer:math-examples3

Conversation

@JackStouffer
Copy link
Contributor

No description provided.

@dlang-bot
Copy link
Contributor

Thanks for your pull request, @JackStouffer!

Bugzilla references

Your PR doesn't reference any Bugzilla issue.

If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub fetch digger
dub run digger -- build "master + phobos#6409"

* $(TR $(TD $(LT)-1.0) $(TD $(NAN)) $(TD no) $(TD yes))
* $(TR $(TD +$(INFIN)) $(TD -$(INFIN)) $(TD no) $(TD no))
* $(TR $(TD $(LT)-1.0) $(TD -$(NAN)) $(TD no) $(TD yes))
* $(TR $(TD +$(INFIN)) $(TD +$(INFIN)) $(TD no) $(TD no))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

these where incorrect

std/math.d Outdated
* A `real`.
*/
real trunc(real x) @trusted nothrow @nogc
auto trunc(real x) @trusted
Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed to auto to auto infer attributes like pure based on implementation without using template

Copy link
Member

Choose a reason for hiding this comment

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

I feel the downside of not documenting the return type outweighs the benefit of attribute inference here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added a note in the docs about the return type

std/math.d Outdated
return core.stdc.math.llroundl(x);
else
assert(0, "lround not implemented");
static assert(0, "lround not implemented");
Copy link
Contributor

@wilzbach wilzbach Apr 2, 2018

Choose a reason for hiding this comment

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

Looks like the remainder isn't available on Win32, but still run?

std\math.d(4908): Error: static assert:  "lround not implemented"

Maybe we should roll a custom, "slow" implementation of it?

edit: probably due to it not being a template

Copy link
Contributor

@wilzbach wilzbach left a comment

Choose a reason for hiding this comment

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

Looks good. We just need to fix the CIs :/

* $(LREF nearbyint) performs the same operation, but does
* not set the FE_INEXACT exception.
*/
real rint(real x) @safe pure nothrow @nogc { pragma(inline, true); return core.math.rint(x); }
Copy link
Contributor

Choose a reason for hiding this comment

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

So we have lround, nearbyint, round and rint which all perform almost the same function. That's not very "abstracted high-level" over C :/

* $(TR $(TD -1.0) $(TD -$(INFIN)) $(TD yes) $(TD no))
* $(TR $(TD $(LT)-1.0) $(TD $(NAN)) $(TD no) $(TD yes))
* $(TR $(TD +$(INFIN)) $(TD -$(INFIN)) $(TD no) $(TD no))
* $(TR $(TD $(LT)-1.0) $(TD -$(NAN)) $(TD no) $(TD yes))
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add an explicit test for this? (i.e. that it's a negative nan)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have a test for this on line 3798, but because -real.nan != -real.nan there's really no way to test this

Copy link
Member

Choose a reason for hiding this comment

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

Use is.

* This is also known as "chop" rounding.
*/
real trunc(real x) @trusted nothrow @nogc
version(StdDdoc)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, so apparently ret in ASM doesn't work with an auto return type. So we now have this mess.

@JackStouffer JackStouffer merged commit 618018e into dlang:master Apr 3, 2018
@JackStouffer JackStouffer deleted the math-examples3 branch April 3, 2018 19:24
dkgroot added a commit to dkgroot-dlang/druntime that referenced this pull request Apr 11, 2018
…te needed for DragonFly.

Caused trouble compiling phobos since dlang/phobos#6409

Phobos Compile Error:
std/math.d(4598): Error: `pure` function `std.math.nearbyint` cannot call impure function `core.stdc.math.nearbyintl`
dkgroot added a commit to dkgroot-dlang/druntime that referenced this pull request Apr 21, 2018
…te needed for DragonFly.

Caused trouble compiling phobos since dlang/phobos#6409

Phobos Compile Error:
std/math.d(4598): Error: `pure` function `std.math.nearbyint` cannot call impure function `core.stdc.math.nearbyintl`
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.

4 participants