Total ordering for floating-point values.#3022
Total ordering for floating-point values.#3022DmitryOlshansky merged 15 commits intodlang:masterfrom
Conversation
|
Maybe return |
|
I agree, returning |
|
I tried to follow semantics described in the standard, and it explicitly specifies the return type as boolean. I'm not sure how important that is, but that was the motivation for the current design. It seems like it would be nice to have 3 functions:
However, having all three is definitely an overkill. So, which one? |
|
I don't see that being overkill in the slightest. |
|
I decided to settle on option 1, because
And I still don't think it's a good idea to have three functions doing the same thing in slightly different ways. |
|
Code style nit, we generally don't put braces around single statements in Phobos. |
std/math.d
Outdated
There was a problem hiding this comment.
So, looking back at this, I have no idea how I failed to notice this. I would suggest an if-else if chain rather than this, as it is much clearer with no difference in performance.
34c6b37 to
9835719
Compare
|
Fixed. |
9835719 to
f472b58
Compare
|
@9il you look like a numerics expert :) Would you mind reviewing this? Thanks! |
|
I'll try:) Thanks! |
There was a problem hiding this comment.
The last else block should always be a static assert.
Here should instead be else static if (F.realFormat == RealFormat.ibmExtended)
There was a problem hiding this comment.
f472b58 to
96227bd
Compare
std/math.d
Outdated
|
|
|
... and one documented unittest for |
|
If this function works faster then naive floating point comparison then we can make it default for functions like |
std/math.d
Outdated
There was a problem hiding this comment.
Nitpick: empty line looks unnecessary here.
|
If this function works faster then naive floating point comparison we can make it default for functions like `sort`.
Well, I was unable to construct a benchmark that would measure just that, so I
have no idea.
|
|
`sort` function has note about floating point. Please add reference to the new function into the `sort` docs.
Hm. I used `$(XREF)` for cross-module referencing, but the resulting link points
to stable docs on dlang.org, which, of course, contain no such function. What
should I do?
|
Nothing. XREF is fine. |
|
LGTM except name |
|
I dunno. The first thing |
|
OT: As we seem to have most D math experts assembled in this thread: Could somebody have a look at this issue: AFAICS std.math.internal.gammafunction is the last module with only works with X86 80bit reals and has never been ported for standard double / float formats. As this probably affects every non X86 architecture it'd be great if somebody could have a look. |
|
Thanks, I had a quick look at |
|
FYI see |
|
Porting is pretty simple except constants. Sometimes they are defined in different binary forms (depends on endianness). The steps can be described as:
|
I'm not familiar with Wolfram, I'd be interested to know how you do this. |
|
@ibuclaw Example: hexadecimal log(2^52). |
|
Also you can press More digits. |
Okay I'm here. Press the button I guess? :) |
|
Yes please =) |
I've added milestone but @ivan-timokhin please consider adding a nice changelog entry or the change may go unnoticed. |
|
Auto-merge toggled on |
Total ordering for floating-point values.
Adds a
totalOrderfunction as specified in IEEE 754-2008.An immediate benefit is the ability to sort arrays of floating-point values and get predictable results even in presence of NaNs (see http://dpaste.dzfl.pl/1f78bc6f7d2b).