Path: news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail From: bart Newsgroups: comp.lang.c Subject: Re: "A diagram of C23 basic types" Date: Fri, 18 Apr 2025 12:49:56 +0100 Organization: A noiseless patient Spider Lines: 62 Message-ID: References: <87y0wjaysg.fsf@gmail.com> <20250407211216.00006238@yahoo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Fri, 18 Apr 2025 13:49:57 +0200 (CEST) Injection-Info: dont-email.me; posting-host="225decbae7f6d1b66db568edbb209aee"; logging-data="3103015"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/27yHbz0voxxz35ORTx4uK" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:4mk4ZYE6fkkPBsatcxFSYqSwcBU= Content-Language: en-GB In-Reply-To: On 18/04/2025 03:39, Lawrence D'Oliveiro wrote: > On Mon, 7 Apr 2025 22:46:49 +0100, bart wrote: > >> (In source code, it would also be useful to use 1e9 or 1e12, >> unfortunately those normally yield floating point values. > > Tried Python: > > >>> type(1e9) > > >>> round(1e9) > 1000000000 > >>> round(1e12) > 1000000000000 > > However: > > >>> round(1e24) > 999999999999999983222784 > > So I tried: > > >>> import decimal > >>> decimal.Decimal("1e24") > Decimal('1E+24') > >>> int(decimal.Decimal("1e24")) > 1000000000000000000000000 > > which is more like it. The idea behind writing 1e12 for example was for something that was compact, quick to type, and easy to grasp. This: int(decimal.Decimal("1e24")) seems to lack all of those. Besides: import decimal def fn(n): for i in range(100_000_000): a = int(decimal.Decimal(n)) print(a) def fn2(n): for i in range(100_000_000): a = round(n) print(a) def fn3(n): for i in range(100_000_000): a = n print(a) fn("1e24") # 50 seconds (loop overheads excluded) fn2(1e15) # 13 seconds fn3(1e15) # 0.6 seconds You don't want it to be much slower either: it should not affect performance. (Timings for CPython.)