Path: csiph.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail From: candycanearter07 Newsgroups: comp.lang.c Subject: Re: Why is this happening? Date: Tue, 31 Mar 2026 19:00:03 -0000 (UTC) Organization: the-candyden-of-code Lines: 35 Message-ID: References: <10q5046$3ec1o$2@dont-email.me> <10q523v$3e865$1@dont-email.me> <10q7bug$7vod$1@dont-email.me> <87bjg8wrgl.fsf@example.invalid> <20260329115057.00003a47@yahoo.com> <87qzp2uzjc.fsf@example.invalid> <10qf4vi$2u7d8$2@dont-email.me> Injection-Date: Tue, 31 Mar 2026 19:00:04 +0000 (UTC) Injection-Info: dont-email.me; posting-host="264c15ef6eb9a115f352c695642abdd8"; logging-data="3787590"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/DRW6P4fxLUoqI8bO581osYla/a3O7p8v02XiuKJmQGA==" User-Agent: slrn/1.0.3 (Linux) Cancel-Lock: sha1:PrdlQEzKMuW1yEQ8VwoXNrFmirI= X-Face: b{dPmN&%4|lEo,wUO\"KLEOu5N_br(N2Yuc5/qcR5i>9-!^e\.Tw9?/m0}/~:UOM:Zf]% b+ V4R8q|QiU/R8\|G\WpC`-s?=)\fbtNc&=/a3a)r7xbRI]Vl)r<%PTriJ3pGpl_/B6!8pe\btzx `~R! r3.0#lHRE+^Gro0[cjsban'vZ#j7,?I/tHk{s=TFJ:H?~=]`O*~3ZX`qik`b:.gVIc-[$t/e ZrQsWJ >|l^I_[pbsIqwoz.WGA] wrote at 00:37 this Tuesday (GMT): > On 2026-03-29 16:54, Keith Thompson wrote: > ... >> context that doesn't need floating-point. I'm not sure whether >> (unsigned long)1e9 is actually guaranteed to yield 1000000000 rather >> than 999999999. Maybe it is, but I don't want to waste brain cells >> proving it. > > I'll waste my brain cells. > > "When a finite value of decimal floating type is converted to an integer > type other than bool, the fractional part is discarded (i.e. the value > is truncated toward zero)." (6.3.2.4p2) > > "For decimal floating literals ... the result is either the nearest > representable value, or the larger or smaller representable value > immediately adjacent to the nearest representable value, chosen in an > implementation-defined manner." (6.4.5.3p4) > > This allows for 1e9 to have a value of exactly 1000000000.0, or slightly > higher, which converts to unsigned long as 1000000000, or a value > slightly less than 1000000000.0, which will convert to 999999999. > > So you were right - don't use floating point to do what integer types > are sufficient to do. Floats should not be used for any kinda comparisons besides basic greater than/less than checks or flooring it beforehand, its just too unreliable. also languages that make no distinguishment are very frustrating sometimes -- user is generated from /dev/urandom