Path: csiph.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Why is this happening? Date: Sun, 29 Mar 2026 16:22:10 -0700 Organization: None to speak of Lines: 66 Message-ID: <87ecl2uspp.fsf@example.invalid> 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> <20260330020523.0000330f@yahoo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Date: Sun, 29 Mar 2026 23:22:11 +0000 (UTC) Injection-Info: dont-email.me; posting-host="1ddb92ea07dcf10ad5bdf45e81a7e5f2"; logging-data="2102851"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19qg2j5aSgTFVCGegQieQd4" User-Agent: Gnus/5.13 (Gnus v5.13) Cancel-Lock: sha1:zJeu0kEdvNnODzrtd+ylmE+PWHY= sha1:mnzcf5vmoK8rmIQi+5xb9fU/FBI= Xref: csiph.com comp.lang.c:397287 Michael S writes: > On Sun, 29 Mar 2026 13:54:47 -0700 > Keith Thompson wrote: >> Michael S writes: >> > On Sat, 28 Mar 2026 15:14:42 GMT >> > scott@slp53.sl.home (Scott Lurndal) wrote: >> > >> >> Keith Thompson writes: >> >> >Lawrence Dג€™Oliveiro writes: >> >> >> On Fri, 27 Mar 2026 10:15:23 +0100, Josef M_¶llers wrote: >> >> >> >> >> >>> diffns += 1000000000UL; >> >> >> >> >> >> Can you write >> >> >> >> >> >> diffns += 1_000_000_000UL; >> >> >> >> >> >> yet? >> >> > >> >> >Not in C. C23 introduces the apostrophe as a digit separator, >> >> >copied from C++: >> >> > >> >> > diffns += 1'000'000'000UL; >> >> >> >> Or diffns += 1000ul * 1000ul * 1000ul; >> >> >> >> or diffns += 1 * NS_PER_SEC; >> >> >> >> with >> >> #define NS_PER_SEC ((1000ul * 1000ul * 1000ul)) >> > >> > Why not (int)1e9 ? >> [...] >> >> Because int is not guaranteed to be wider than 16 bits (though if >> you're already relying on Windows or POSIX, you can assume it's at >> least 32 bits). The original expression was of type unsigned long, >> so (unsigned long)1e9 would be more nearly correct. >> >> And because it's a floating-point to integer conversion in a >> 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. > > IEEE binary64 has precise representations for all powers of 10 from 1e0 > to 1e22. I.e it covers all powers of 10 that fit within 64-bit unsigned > integer with 3 values to spare. Sure, but the C standard doesn't guarantee IEEE-compatible floating-point. I'd be very surprised if any C implementation had (unsigned long)1e9 unequal to 1000000000. If I ran across one, I'd seriously consider submitting a bug report. I'd have to study the C standard's floating-point requirements to be sure (I haven't done that yet). My point is that writing (unsigned long)1e9 rather than 1000000000 or (1000ul * 1000ul * 1000ul) introduces complications I'd rather avoid. It *might* be perfectly safe, but I'm uncomfortable relying on it. If nothing else, if the program misbehaves, it's one less thing to worry about while tracking down the bug. -- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com void Void(void) { Void(); } /* The recursive call of the void */