February 25, 2018
On Sunday, 25 February 2018 at 09:30:12 UTC, psychoticRabbit wrote:
> I would have preffered it defaulted java style ;-)
>
> System.out.println(1.0); // i.e. it prints 'what I told it to print'.

System.out.println(1.0); // print 1.0
System.out.println(1.00000); // print 1.0

So it doesn't print "what you told it to print"

Andrea Fontana
February 25, 2018
On Sunday, 25 February 2018 at 12:13:31 UTC, Andrea Fontana wrote:
> On Sunday, 25 February 2018 at 09:30:12 UTC, psychoticRabbit wrote:
>> I would have preffered it defaulted java style ;-)
>>
>> System.out.println(1.0); // i.e. it prints 'what I told it to print'.
>
> System.out.println(1.0); // print 1.0
> System.out.println(1.00000); // print 1.0
>
> So it doesn't print "what you told it to print"
>
> Andrea Fontana

can someone please design a language that does what I tell it!

please!!

is that so hard??

print 1.0 does not mean go and print 1 .. it means go and print 1.0

languages are too much like people.. always thinking for themselves.

I fed up!

fed up I say!

February 25, 2018
On 2/25/18 8:33 AM, psychoticRabbit wrote:
> On Sunday, 25 February 2018 at 12:13:31 UTC, Andrea Fontana wrote:
>> On Sunday, 25 February 2018 at 09:30:12 UTC, psychoticRabbit wrote:
>>> I would have preffered it defaulted java style ;-)
>>>
>>> System.out.println(1.0); // i.e. it prints 'what I told it to print'.
>>
>> System.out.println(1.0); // print 1.0
>> System.out.println(1.00000); // print 1.0
>>
>> So it doesn't print "what you told it to print"
>>
>> Andrea Fontana
> 
> can someone please design a language that does what I tell it!
> 
> please!!
> 
> is that so hard??
> 
> print 1.0 does not mean go and print 1 .. it means go and print 1.0
> 

1 == 1.0, no?

You are printing a value, which means it has to go through a conversion from the value to a string (i.e. printable). writefln has no idea what you wrote as a literal, it just sees the value 1 (as a double). I hope we never make a distinction here!

If you want to tell it EXACTLY what to print, print a string:

writeln("1.0");

-Steve
February 25, 2018
On Sunday, 25 February 2018 at 13:33:07 UTC, psychoticRabbit wrote:
> can someone please design a language that does what I tell it!
>
> please!!
>
> is that so hard??
>
> print 1.0 does not mean go and print 1 .. it means go and print 1.0
>
> languages are too much like people.. always thinking for themselves.
>
> I fed up!
>
> fed up I say!

That's in fact a data representation problem not a language problem. In C#, if you are using a *decimal* data type, it prints as expected:

decimal one = 1m;       //internally represented as 10^^0
decimal one2 = 1.0m;    //internally represented as 10^^-1
decimal one3 = 1.00m;   //internally represented as 100^^-2
//one == one2 == one3, but the output is different:
Console.WriteLine(one);  //outputs 1
Console.WriteLine(one2); //outputs 1.0
Console.WriteLine(one3); //outputs 1.00

Nor Java and nor D have any built-in decimal type, therefore the internal representation of floating point values is always double (or float, or real). Double has a unique representation for 1, 1.0 or 1.00 and it's always 2^^0. How the writeln/println functions outputs 2^0, it's a design decision. Since D is inheriting C concepts (including printf), it will use the %g format as in C. I'm not a Java fan, therefore I don't know what was behind the decision of the language creators to output floating point values with at least one decimal digit.
February 26, 2018
On Sunday, 25 February 2018 at 13:33:07 UTC, psychoticRabbit wrote:
> On Sunday, 25 February 2018 at 12:13:31 UTC, Andrea Fontana wrote:
>> On Sunday, 25 February 2018 at 09:30:12 UTC, psychoticRabbit wrote:
>>> I would have preffered it defaulted java style ;-)
>>>
>>> System.out.println(1.0); // i.e. it prints 'what I told it to print'.
>>
>> System.out.println(1.0); // print 1.0
>> System.out.println(1.00000); // print 1.0
>>
>> So it doesn't print "what you told it to print"
>>
>> Andrea Fontana
>
> can someone please design a language that does what I tell it!
>
> please!!
>
> is that so hard??
>
> print 1.0 does not mean go and print 1 .. it means go and print 1.0
>
> languages are too much like people.. always thinking for themselves.
>
> I fed up!
>
> fed up I say!

Don't worry little rabbit 1 == 1.0 so it is OK.
February 26, 2018
On Sunday, 25 February 2018 at 14:52:19 UTC, Steven Schveighoffer wrote:
>
> 1 == 1.0, no?

no. at least, not when a language forces you to think in terms of types.

1 is an int.
1.0 is a floating point.

I admit, I've never printed output without using format specifiers, but still, if I say write(1.0), it should not go off and print what looks to me, like an int.

Inheriting crap from C is no excuse ;-)

and what's going on here btw?

assert( 1 == 1.000000000000000001 );  // assertion error in DMD but not in LDC
assert( 1 == 1.0000000000000000001 );  // no assertion error??

(compiled in 64bit mode)
February 26, 2018
On Mon, Feb 26, 2018 at 11:34:06PM +0000, psychoticRabbit via Digitalmars-d-learn wrote: [...]
> and what's going on here btw?
> 
> assert( 1 == 1.000000000000000001 );  // assertion error in DMD but not in
> LDC
> assert( 1 == 1.0000000000000000001 );  // no assertion error??
> 
> (compiled in 64bit mode)

A 64-bit double can only hold about 14-15 decimal digits of precision. Anything past that, and there's a chance your "different" numbers are represented by exactly the same bits and the computer can't tell the difference.

If you want arbitrary precision you'll have to use an arbitrary precision library like GMP.  It will be a lot slower than built-in floats or doubles, though.

In general, real numbers have an infinite number of digits, and so would require infinite memory and infinite time to perform any computations at all.  What we have now is a reasonably practical compromise. :-D  But that also means there will be some inherent inexactness because we're trying to represent an infinite number of digits in a small, finite space.

(There *are* exact representations for certain subsets of irrationals that allow fast computation that does not lose precision. But generally, they are only useful for specific applications where you know beforehand what form(s) your numbers will take. For general arithmetic, you have to compromise between speed and accuracy.)


T

-- 
In theory, software is implemented according to the design that has been carefully worked out beforehand. In practice, design documents are written after the fact to describe the sorry mess that has gone on before.
February 26, 2018
On Monday, February 26, 2018 16:04:59 H. S. Teoh via Digitalmars-d-learn wrote:
> On Mon, Feb 26, 2018 at 11:34:06PM +0000, psychoticRabbit via Digitalmars-d-learn wrote: [...]
>
> > and what's going on here btw?
> >
> > assert( 1 == 1.000000000000000001 );  // assertion error in DMD but not
> > in LDC
> > assert( 1 == 1.0000000000000000001 );  // no assertion error??
> >
> > (compiled in 64bit mode)
>
> A 64-bit double can only hold about 14-15 decimal digits of precision. Anything past that, and there's a chance your "different" numbers are represented by exactly the same bits and the computer can't tell the difference.
>
> If you want arbitrary precision you'll have to use an arbitrary precision library like GMP.  It will be a lot slower than built-in floats or doubles, though.
>
> In general, real numbers have an infinite number of digits, and so would require infinite memory and infinite time to perform any computations at all.  What we have now is a reasonably practical compromise. :-D  But that also means there will be some inherent inexactness because we're trying to represent an infinite number of digits in a small, finite space.
>
> (There *are* exact representations for certain subsets of irrationals that allow fast computation that does not lose precision. But generally, they are only useful for specific applications where you know beforehand what form(s) your numbers will take. For general arithmetic, you have to compromise between speed and accuracy.)

No. No. No. Floating point values are just insane. ;)

http://dconf.org/2016/talks/clugston.html

In all seriousness, floating point values do tend to be highly frustrating to deal with, and personally, I've gotten to the point that I generally avoid them unless I need them. And much as that talks is titled "Using Floating Point Without Losing Your Sanity," I came away from it even more convinced that avoiding floating point values is pretty much the only sane solution - though unfortunately, sometimes, you really don't have a choice.

- Jonathan M Davis

February 27, 2018
On Tuesday, 27 February 2018 at 00:04:59 UTC, H. S. Teoh wrote:
>
> A 64-bit double can only hold about 14-15 decimal digits of precision. Anything past that, and there's a chance your "different" numbers are represented by exactly the same bits and the computer can't tell the difference.
>
> T

I really miss not having a (C# like) decimal type.

February 26, 2018
On Tue, Feb 27, 2018 at 12:26:56AM +0000, psychoticRabbit via Digitalmars-d-learn wrote:
> On Tuesday, 27 February 2018 at 00:04:59 UTC, H. S. Teoh wrote:
> > 
> > A 64-bit double can only hold about 14-15 decimal digits of precision.  Anything past that, and there's a chance your "different" numbers are represented by exactly the same bits and the computer can't tell the difference.
> > 
> > T
> 
> I really miss not having a (C# like) decimal type.

Didn't somebody write a decimal library type recently?  Try searching on code.dlang.org, you can probably find it there.


T

-- 
They say that "guns don't kill people, people kill people." Well I think the gun helps. If you just stood there and yelled BANG, I don't think you'd kill too many people. -- Eddie Izzard, Dressed to Kill