Deutsch   English   Français   Italiano  
<vtte95$2um97$1@dont-email.me>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail
From: bart <bc@freeuk.com>
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: <vtte95$2um97$1@dont-email.me>
References: <87y0wjaysg.fsf@gmail.com> <vsj1m8$1f8h2$1@dont-email.me>
 <vsj2l9$1j0as$1@dont-email.me> <vsjef3$1u4nk$1@dont-email.me>
 <vsjg6t$20pdb$1@dont-email.me> <vsjgjn$1v1n4$1@dont-email.me>
 <vsjk4k$24q5m$1@dont-email.me> <vsjlcp$230a5$1@dont-email.me>
 <vsni1v$291i3$5@dont-email.me> <vt13vp$bjs0$1@dont-email.me>
 <20250407211216.00006238@yahoo.com> <vt14u7$bjs0$2@dont-email.me>
 <vt1bmt$jf54$1@dont-email.me> <vt1h48$n5fs$1@dont-email.me>
 <vtse0n$1uc55$7@dont-email.me>
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: <vtse0n$1uc55$7@dont-email.me>

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)
>      <class 'float'>
>      >>> 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.)