So why double to float conversion is implicit ?

codephantom me at noyb.com
Mon Oct 23 10:05:49 UTC 2017


On Saturday, 21 October 2017 at 20:17:12 UTC, NX wrote:
> I think this is a serious topic and needs clarification.

Just out of interest, as opposed to wanting to debate the 
merits...

I did a little investigation of how various languages deal with 
floating point precision (by default) for standard output. It is 
certainly interesting that there are differences - mostly one way 
or the other, rather than huge differences.


C
-------
double d = 1.12345678912345;
printf("%lf\n", d);  // C writes -> 1.123457 (some rounding here)


C++
----
double d = 1.12345678912345;
std::cout << d << std::endl; // c++ writes -> 1.123456


Rust
----
let d = 1.12345678912345;
println!("{}", d); // Rust writes -> 1.1234568 (some rounding 
here)


D
---
double d = 1.12345678912345;
writeln(d); // D writes -> 1.12346



Java
----
double d = 1.12345678912345;
System.out.println(d); // java writes -> 1.12345678912345


C#
----
double d = 1.12345678912345;
System.Console.WriteLine(d); // C# writes -> 1.12345678912345


Python
------
d = 1.12345678912345;
print(d); // python writes -> 1.12345678912345


Go
---
d := 1.12345678912345;
fmt.Println(d); // Go prints -> 1.12345678912345


Swift
-----
let d = 1.12345678912345;
print(d); // Swift prints -> 1.12345678912345





More information about the Digitalmars-d mailing list