Re: Handling big FP numbers

2019-02-12 Thread Guillaume Piolat via Digitalmars-d-learn
On Saturday, 9 February 2019 at 02:54:18 UTC, Adam D. Ruppe wrote: (The `real` thing in D was a massive mistake. It is slow and adds nothing but confusion.) We've had occasional problems with `real` being 80-bit on FPU giving more precision than asked, and effectively hiding 32-bit float pr

Re: Handling big FP numbers

2019-02-12 Thread Simen Kjærås via Digitalmars-d-learn
On Tuesday, 12 February 2019 at 09:20:27 UTC, Aurélien Plazzotta wrote: Thank you both for your lesson Adam D. Ruppe and H.S. Teoh. Is there a wish or someone showing one's intention to implement into the language the hypothetical built-in 128 bit types via the "cent" and "ucent" reserved keywo

Re: Handling big FP numbers

2019-02-12 Thread Aurélien Plazzotta via Digitalmars-d-learn
On Saturday, 9 February 2019 at 03:03:41 UTC, H. S. Teoh wrote: If you want to hold more than 15 digits, you'll either have to use `real`, which depending on your CPU will be 80-bit (x86) or 128-bit (a few newer, less common CPUs), or an arbitrary-precision library that simulates larger precis

Re: Handling big FP numbers

2019-02-10 Thread Murilo via Digitalmars-d-learn
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 ac

Re: Handling big FP numbers

2019-02-10 Thread Dennis via Digitalmars-d-learn
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

Re: Handling big FP numbers

2019-02-10 Thread Murilo via Digitalmars-d-learn
On Saturday, 9 February 2019 at 05:46:22 UTC, H. S. Teoh wrote: On Sat, Feb 09, 2019 at 03:52:38AM +, Murilo via Digitalmars-d-learn wrote: On Saturday, 9 February 2019 at 03:28:24 UTC, Adam D. Ruppe wrote: [...] > But you can change this with the format specifiers (use > `writefln` instea

Re: Handling big FP numbers

2019-02-08 Thread John via Digitalmars-d-learn
On Saturday, 9 February 2019 at 02:12:29 UTC, Murilo wrote: Why is it that in C when I attribute the number 991234307654329925.7865 to a double it prints 991234299470108672. and in D it prints 9912342990. ? Apparently both languages cause a certain loss

Re: Handling big FP numbers

2019-02-08 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Feb 09, 2019 at 04:36:26AM +, DanielG via Digitalmars-d-learn wrote: > On Saturday, 9 February 2019 at 04:32:44 UTC, Murilo wrote: > > Thank you very much for clearing this up. But how do I make D > > behave just like C? Is there a way to do that? > > Off the top of my head, you'd have

Re: Handling big FP numbers

2019-02-08 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Feb 09, 2019 at 03:52:38AM +, Murilo via Digitalmars-d-learn wrote: > On Saturday, 9 February 2019 at 03:28:24 UTC, Adam D. Ruppe wrote: [...] > > But you can change this with the format specifiers (use `writefln` > > instead of `writeln` and give a precision argument) or, of course, >

Re: Handling big FP numbers

2019-02-08 Thread Murilo via Digitalmars-d-learn
On Saturday, 9 February 2019 at 04:36:26 UTC, DanielG wrote: On Saturday, 9 February 2019 at 04:32:44 UTC, Murilo wrote: Thank you very much for clearing this up. But how do I make D behave just like C? Is there a way to do that? Off the top of my head, you'd have to link against libc so you

Re: Handling big FP numbers

2019-02-08 Thread DanielG via Digitalmars-d-learn
On Saturday, 9 February 2019 at 04:32:44 UTC, Murilo wrote: Thank you very much for clearing this up. But how do I make D behave just like C? Is there a way to do that? Off the top of my head, you'd have to link against libc so you could use printf() directly. But may I ask why that is so im

Re: Handling big FP numbers

2019-02-08 Thread Murilo via Digitalmars-d-learn
On Saturday, 9 February 2019 at 04:30:22 UTC, DanielG wrote: On Saturday, 9 February 2019 at 03:33:13 UTC, Murilo wrote: Thanks but here is the situation, I use printf("%.20f", 0.1); in both C and D, C returns 0.1555 whereas D returns 0.10001000. So I understand your

Re: Handling big FP numbers

2019-02-08 Thread DanielG via Digitalmars-d-learn
On Saturday, 9 February 2019 at 03:33:13 UTC, Murilo wrote: Thanks but here is the situation, I use printf("%.20f", 0.1); in both C and D, C returns 0.1555 whereas D returns 0.10001000. So I understand your point, D rounds off more, but that causes loss of precision,

Re: Handling big FP numbers

2019-02-08 Thread Murilo via Digitalmars-d-learn
On Saturday, 9 February 2019 at 03:28:24 UTC, Adam D. Ruppe wrote: On Saturday, 9 February 2019 at 03:21:51 UTC, Murilo wrote: Now, changing a little bit the subject. All FPs in D turn out to be printed differently than they are in C and in C it comes out a little more precise than in D. Is thi

Re: Handling big FP numbers

2019-02-08 Thread Murilo via Digitalmars-d-learn
On Saturday, 9 February 2019 at 03:28:24 UTC, Adam D. Ruppe wrote: On Saturday, 9 February 2019 at 03:21:51 UTC, Murilo wrote: Now, changing a little bit the subject. All FPs in D turn out to be printed differently than they are in C and in C it comes out a little more precise than in D. Is thi

Re: Handling big FP numbers

2019-02-08 Thread Adam D. Ruppe via Digitalmars-d-learn
On Saturday, 9 February 2019 at 03:21:51 UTC, Murilo wrote: Now, changing a little bit the subject. All FPs in D turn out to be printed differently than they are in C and in C it comes out a little more precise than in D. Is this really supposed to happen? Like I said in my first message, the

Re: Handling big FP numbers

2019-02-08 Thread Murilo via Digitalmars-d-learn
On Saturday, 9 February 2019 at 03:03:41 UTC, H. S. Teoh wrote: On Sat, Feb 09, 2019 at 02:12:29AM +, Murilo via Digitalmars-d-learn wrote: Why is it that in C when I attribute the number 991234307654329925.7865 to a double it prints 991234299470108672. and in D it print

Re: Handling big FP numbers

2019-02-08 Thread DanielG via Digitalmars-d-learn
On Saturday, 9 February 2019 at 03:03:41 UTC, H. S. Teoh wrote: It's not only because of converting decimal to binary, it's also because double only has 64 bits to store information, and your number has far more digits than can possibly fit into 64 bits. Adding to that, here's a nice little o

Re: Handling big FP numbers

2019-02-08 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Feb 09, 2019 at 02:54:18AM +, Adam D. Ruppe via Digitalmars-d-learn wrote: [...] > (The `real` thing in D was a massive mistake. It is slow and adds > nothing but confusion.) Yeah, it is also the only variable-width built-in type in D, which makes it a wart in an otherwise elegant sys

Re: Handling big FP numbers

2019-02-08 Thread Murilo via Digitalmars-d-learn
On Saturday, 9 February 2019 at 02:54:18 UTC, Adam D. Ruppe wrote: On Saturday, 9 February 2019 at 02:46:52 UTC, Murilo wrote: But I used the type double in D which is supposed to be only 64 bits long and not 80 bits long, the type real is the one which is supposed to be 80 bits long. Right?

Re: Handling big FP numbers

2019-02-08 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Feb 09, 2019 at 02:12:29AM +, Murilo via Digitalmars-d-learn wrote: > Why is it that in C when I attribute the number > 991234307654329925.7865 to a double it prints > 991234299470108672. and in D it prints > 9912342990. ? Apparently both language

Re: Handling big FP numbers

2019-02-08 Thread Adam D. Ruppe via Digitalmars-d-learn
On Saturday, 9 February 2019 at 02:46:52 UTC, Murilo wrote: But I used the type double in D which is supposed to be only 64 bits long and not 80 bits long, the type real is the one which is supposed to be 80 bits long. Right? Right, BUT the compile time stuff is done before that. double a = 1

Re: Handling big FP numbers

2019-02-08 Thread Murilo via Digitalmars-d-learn
On Saturday, 9 February 2019 at 02:42:09 UTC, Adam D. Ruppe wrote: On Saturday, 9 February 2019 at 02:12:29 UTC, Murilo wrote: prints Two likely reasons: the D compiler does compile time stuff at 80 bit, whereas the C++ one probably uses 64 bit, and the D default print rounds more aggressive

Re: Handling big FP numbers

2019-02-08 Thread Adam D. Ruppe via Digitalmars-d-learn
On Saturday, 9 February 2019 at 02:12:29 UTC, Murilo wrote: prints Two likely reasons: the D compiler does compile time stuff at 80 bit, whereas the C++ one probably uses 64 bit, and the D default print rounds more aggressively than default C++ printing. It is useful to put stuff in runtime

Handling big FP numbers

2019-02-08 Thread Murilo via Digitalmars-d-learn
Why is it that in C when I attribute the number 991234307654329925.7865 to a double it prints 991234299470108672. and in D it prints 9912342990. ? Apparently both languages cause a certain loss of precision(which is part of converting the decimal system