Fun with floating point

2015-02-07 Thread Kenny via Digitalmars-d-learn
Hi, D community! I have this program: import std.stdio; import std.conv; int main(string[] argv) { float eps = 1.0f; float f = 0.0f; while (f + eps != f) f += 1.0f; writeln(eps = ~ to!string(eps) ~ , max_f = ~ to!string(f)); return 0; } According to

Re: Fun with floating point

2015-02-07 Thread Kenny via Digitalmars-d-learn
And sory for the typos, cannot find edit functionality here..

Re: Fun with floating point

2015-02-08 Thread Kenny via Digitalmars-d-learn
nope, this is a bug in your code. compiler (by the specs) is free to perform intermediate calculations with any precision that is not lower than a highest used type (i.e. not lower that `float`'s one for `while` condition (`f + eps != f`). it may be even infinite precision, so your code may

Re: Fun with floating point

2015-02-08 Thread Kenny via Digitalmars-d-learn
For example, according to IEEE-754 specification if we work with 32bit floating point numbers (floats in D) then the following pseudo code prints 'Works'. F32 f = 16777216.0f; F32 f2 = f + 0.1f; if is_the_same_binary_presentation(f, f2) Print(Works); As I understand D does not guarantee

Re: Fun with floating point

2015-02-08 Thread Kenny via Digitalmars-d-learn
i think you are mixing two things here. IEEE doesn't specify which internal representation compilers should use, it only specifies the results for chosen representation. so if D specs states that `float` calculations are always performing with `float` precision (and specs aren't), your sample

Re: Fun with floating point

2015-02-08 Thread Kenny via Digitalmars-d-learn
There is no right or wrong when you compare floating point values for equality (and inequality) unless those values can be represented exactly in the machine. 1.0 is famously not representable exactly. (It is similar to how 1/3 cannot be represented in the decimal system.) Here I tested one

Re: Best practices for reading public interfaces

2015-02-22 Thread Kenny via Digitalmars-d-learn
On Sunday, 22 February 2015 at 12:13:02 UTC, MrSmith wrote: You can also fold all the function bodies in your editor, this helps me to read massive sources. Oh, I almost forgot about this feature, never used it in C++ but for D it looks promising. Thanks!

Re: Best practices for reading public interfaces

2015-02-22 Thread Kenny via Digitalmars-d-learn
On Saturday, 21 February 2015 at 20:56:26 UTC, anonymous wrote: On Saturday, 21 February 2015 at 20:46:09 UTC, Kenny wrote: b) Write DDocs and read documentation. The problem here is that I'm going to use D only for my own projects and in the last time I tend to write less documentation, for

Best practices for reading public interfaces

2015-02-21 Thread Kenny via Digitalmars-d-learn
I like D modules and it's a major point in the list of major points why I like D (there is also the second not so nice wft-list but it's for another post). I'm annoyed with C++ includes and I'm tired to create 2 files every time when I need to add something new to the project... But I must admit

readText for large files on Windows.

2015-04-19 Thread Kenny via Digitalmars-d-learn
This function works fine for large text files like 100Mb or 1Gb but failed when I tried to read 6Gb file. This happens on Windows x64. The possible reason that it uses read(in char[], size_t) function and on windows it calls GetFileSize. This function returns file size as 32 bit value. If

Re: readText for large files on Windows.

2015-04-20 Thread Kenny via Digitalmars-d-learn
Thanks. The bug is created. https://issues.dlang.org/show_bug.cgi?id=14469