Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > fr.comp.lang.python > #3947

Re: Affichage en notation scientifique.

Path csiph.com!news.mixmin.net!aioe.org!K7PIs9tCGQ+WHJa7e6BylQ.user.46.165.242.75.POSTED!not-for-mail
From Alain Ketterlin <alain@universite-de-strasbourg.fr.invalid>
Newsgroups fr.comp.lang.python
Subject Re: Affichage en notation scientifique.
Date Wed, 14 Sep 2022 16:37:36 +0200
Organization Université de Strasbourg
Message-ID <87a672xbrj.fsf@universite-de-strasbourg.fr.invalid> (permalink)
References <tfsmg1$2vqdl$1@dont-email.me>
Mime-Version 1.0
Content-Type text/plain; charset=utf-8
Content-Transfer-Encoding quoted-printable
Injection-Info gioia.aioe.org; logging-data="3155"; posting-host="K7PIs9tCGQ+WHJa7e6BylQ.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux)
X-Notice Filtered by postfilter v. 0.9.2
Cancel-Lock sha1:AYKe/sX3hqqHh2Hyy6myNI9MS/0=
Xref csiph.com fr.comp.lang.python:3947

Show key headers only | View raw


Dominique <zzz@aol.com> writes:

> Je m'amuse avec « 100 énigmes mathématique123654789s résolues avec Python »
>
> Soit t=1236354, est-il possible d'avoir ce nombre en notation
> scientifique 1.236354e6 et récupérer dans une variable l'exposant (6
> ici) ?

Il y a deux choses complètement différentes dans ta question :

1) pour formater un flottant en notation scientifique :

    "%e" % (123456.0) # ou "{:e}".format (123456.0)

   avec des tas de variantes (cf.
   https://docs.python.org/3/library/string.html#formatspec)

2) Pour extraire mantisse est exposant, il y a math.frexp, mais

    >>> math.frexp (123456.0)
    (0.94189453125, 17)

   Tout est normal : dans le codage IEEE 754 (utilisé par Python et le
   reste du monde), mantisse et exposant sont codés en binaire (pour le
   dire vite), et c'est ça qu'on récupère. Bien sûr, m*2**e est égal au
   nombre initial.

   Si par contre tu veux tout cela "en base 10", tu peux jongler avec
   math.floor (math.log10 (...)), qui te donnera l'exposant. Il faut
   ensuite diviser explicitement (et gérer le signe à part). Je ne
   connais pas de raccourci.

-- Alain.

Back to fr.comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Affichage en notation scientifique. Dominique <zzz@aol.com> - 2022-09-14 15:55 +0200
  Re: Affichage en notation scientifique. Dominique <zzz@aol.com> - 2022-09-14 16:17 +0200
  Re: Affichage en notation scientifique. Alain Ketterlin <alain@universite-de-strasbourg.fr.invalid> - 2022-09-14 16:37 +0200
    Re: Affichage en notation scientifique. Dominique <zzz@aol.com> - 2022-09-14 17:25 +0200
      Re: Affichage en notation scientifique. Dominique <zzz@aol.com> - 2022-09-14 18:33 +0200
      Re: Affichage en notation scientifique. Alain Ketterlin <alain@universite-de-strasbourg.fr.invalid> - 2022-09-14 18:59 +0200

csiph-web