Bug 18227 – Assertion failure in iota for floating point

Status
NEW
Severity
normal
Priority
P3
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2018-01-11T21:04:26Z
Last change time
2024-12-01T16:31:53Z
Assigned to
No Owner
Creator
briancschott
Moved to GitHub: phobos#10290 →

Comments

Comment #0 by briancschott — 2018-01-11T21:04:26Z
std.range.package.iota has a bug in how it calculates the number of steps to take. The following inputs cause a to!size_t() to round a 999.9999999 down instead of up to 1000, which then causes an assert failure. ------------------------- import std.range; void main() { iota(8.5300000000000011, 438.17803623529841, 0.4296480362352984); } ------------------------- $ rdmd test.d core.exception.AssertError@/home/brian/.dvm/compilers/dmd-2.078.0/linux/bin/../../src/phobos/std/range/package.d(5594): Assertion failure ---------------- ??:? _d_assertp [0x96e25d65] ??:? pure ref @safe std.range.iota!(double, double, double).iota(double, double, double).Result std.range.iota!(double, double, double).iota(double, double, double).Result.__ctor(double, double, double) [0x96e252fe] ??:? pure @safe std.range.iota!(double, double, double).iota(double, double, double).Result std.range.iota!(double, double, double).iota(double, double, double) [0x96e251c0] ??:? _Dmain [0x96e250e7]
Comment #1 by dlang — 2019-09-08T11:14:38Z
While looking at that problem, I found some related problems: ------ iota(-5.0,double.max,1.0) leeds to "Conversion positive overflow", due to end-start = +infinity ------ iota(0.0,1e30,1.0); leeds to "Conversion positive overflow", due to 1e30 > long.max ------ import std.math: nextUp; iota(0.0,1.0,nextUp(0.0)); leeds to "Conversion positive overflow", due to > long.max potential elements ------ iota(1,1+2*float.epsilon,float.epsilon/4) Works at the moment, but might lead to an endless loop, depending on the bugfix.
Comment #2 by bugzilla — 2019-12-03T16:09:53Z
See https://forum.dlang.org/thread/[email protected] for some discussion on this.
Comment #3 by bugzilla — 2021-03-20T16:43:33Z
I discovered an old PR, trying to fix this: https://github.com/dlang/phobos/pull/6027
Comment #4 by robert.schadek — 2024-12-01T16:31:53Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/phobos/issues/10290 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB