Issue 15466 - Incorrect result for 'real'
Summary: Incorrect result for 'real'
Status: RESOLVED WORKSFORME
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86_64 Linux
: P1 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-12-22 00:43 UTC by Ali Cehreli
Modified: 2022-10-24 15:47 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Ali Cehreli 2015-12-22 00:43:23 UTC
I was able to reduce the code to the following, which involves std.datetime.benchmark. However, I have not investigated whether this is a compiler or Phobos bug. Hence the vague subject. :(

The bug manifests itself only if the four conditions are satisfied in the reduced code (-O, -inline, etc. do not make any difference):

import std.stdio;
import std.datetime;

alias T = real;     // Must be 'real'
enum testCount = 7; // Must be > 6

T foo() {           // Must return a value
    return 42;
}

void main() {
                    // Must cast to void
    const m = benchmark!(() => cast(void)foo)(testCount);
    writeln(m[0].msecs);
}

The output of the program (test measurement) is not 0 (or a very small number of milliseconds) as one would expect:

-9223372036854775808

Ali
Comment 1 RazvanN 2022-10-24 13:45:31 UTC
Hi, Ali!

I was not able to compile your initial code in the bug report, so I slightly modified it to compile:

```d
import std.stdio;
import std.datetime.stopwatch;    // this was `import std.datetime;`

alias T = real;     // Must be 'real'
enum testCount = 7; // Must be > 6

T foo() {           // Must return a value
    return 42; 
}

void main() {
                    // Must cast to void
    const m = benchmark!(() => cast(void)foo)(testCount);
    writeln(m[0].total!"msecs");  // this was `writeln(m[0].msecs);`                                                                                                         
}
```

Running this code yields `0`.

I will close this as WORKSFORME, but please reopen if there is anything that I am missing.
Comment 2 Ali Cehreli 2022-10-24 15:47:34 UTC
Thanks! Works for me as well.