Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
Win64: set FPU CW to 64-bit, set sprintf output format to 2 digits in…
Browse files Browse the repository at this point in the history
… exponents
  • Loading branch information
rainers committed Jul 14, 2013
1 parent d46b4eb commit 277da01
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/core/stdc/stdio.d
Expand Up @@ -613,6 +613,9 @@ else version( Win64 )
int _vsnprintf(char* s, size_t n, in char* format, va_list arg);
alias _vsnprintf vsnprintf;

uint _set_output_format(uint format);
enum _TWO_DIGIT_EXPONENT = 1;

int _filbuf(FILE *fp);
int _flsbuf(int c, FILE *fp);

Expand Down
14 changes: 14 additions & 0 deletions src/rt/dmain2.d
Expand Up @@ -429,6 +429,20 @@ extern (C) int _d_run_main(int argc, char **argv, MainFunc mainFunc)
stdin = &fp[0];
stdout = &fp[1];
stderr = &fp[2];

// ensure that sprintf generates only 2 digit exponent when writing floating point values
_set_output_format(_TWO_DIGIT_EXPONENT);

//_set_controlfp(_PC_64, _MCW_PC); // full precision for reals
asm
{
push RAX;
fstcw word ptr [RSP];
or [RSP], 0b11_00_111111; // 11: use 64 bit extended-precision
// 111111: mask all FP exceptions
fldcw word ptr [RSP];
pop RAX;
}
}

_STI_monitor_staticctor();
Expand Down

0 comments on commit 277da01

Please sign in to comment.