Infinitely summing 0.1 gives error

Hello! The following little program should run forever (until overflow, maybe)

var x = 0.0;
while true do {
   x += 0.1;
   writeln(x);
}

but instead it stops after some time with the following last lines of output:
1.03101e+05
1.03101e+05
1.03101e+05
1.03101e+05
uncaught SystemError: Invalid argument: internal error (while writing real(64) with path "/dev/pts/0" offset 8257534)
inf.chpl:4: thrown here
inf.chpl:4: uncaught here

C and Python versions happily go on forever. I believe this is a bug ...

1 Like

this one, however, works fine (or at least for a much longer time):

var x = 0.0;
while true do {
   x += 0.1;
   writef("%30r\n",x);
}

Hi nelsonluisdias -

Thanks very much for letting us know about this bug. We usually track bug reports as GitHub issues and so I went ahead and created Infinitely summing 0.1 gives error · Issue #17170 · chapel-lang/chapel · GitHub for it.

I have prepared a fix for this bug in this PR fix I/O bug in _ftoa_core to solve issue 17170 by mppf · Pull Request #17171 · chapel-lang/chapel · GitHub which I expect to merge once testing is complete. It should be available in the upcoming 1.24 release.

2 Likes

Hi Michael,

Great to know! Looking forward to 1.24

Cheers
Nelson