Handling big FP numbers
Murilo
murilomiranda92 at hotmail.com
Sun Feb 10 22:19:59 UTC 2019
On Sunday, 10 February 2019 at 21:27:43 UTC, Dennis wrote:
> On Sunday, 10 February 2019 at 20:25:02 UTC, Murilo wrote:
>> It seems this is a feature of D I will have to get used to and
>> accept the fact I can't always get the same number as in C
>
> What compilers and settings do you use? What you're actually
> comparing here are different implementations of the C runtime
> library.
>
> ```
> #include<stdio.h>
>
> int main() {
> double a = 99999912343000007654329925.7865;
> printf("%f\n", a);
> return 0;
> }
> ```
>
> I compiled this with different C compilers on Windows 10 and
> found:
>
> DMC: 99999912342999999472000000.000000
> GCC: 99999912342999999000000000.000000
> CLANG: 99999912342999999470108672.000000
>
> As for D:
> ```
> import core.stdc.stdio: printf;
>
> int main() {
> double a = 99999912343000007654329925.7865;
> printf("%f\n", a);
> return 0;
> }
> ```
>
> DMD: 99999912342999999472000000.000000
> LDC: 99999912342999999470108672.000000
>
> DMC and DMD both use the Digital Mars runtime by default. I
> think CLANG and LDC use the static libcmt by default while GCC
> uses the dynamic msvcrt.dll (not sure about the exact one, but
> evidently it's different). So it really hasn't anything to do
> with D vs. C but rather what C runtime you use.
Ahhh, alright, I was not aware of the fact that there are
different runtimes, thanks for clearing this up.
More information about the Digitalmars-d-learn
mailing list