Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
1334 connectés 

  FORUM HardWare.fr
  Programmation
  C

  Format et précision d'un float (google n'est pas mon amis). Debutant

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

Format et précision d'un float (google n'est pas mon amis). Debutant

n°1741635
jijiz
Posté le 05-06-2008 à 09:11:56  profilanswer
 

Salut à tous et à toutes,
 
Je cherche depuis 10 minutes un petit cours pour formater les float, je me rappelle que l'on peut préciser le nombre de décimales à stocker. Seulement, j'aimerais trouver un cours détaillé sur ce formatage, or je ne trouve rien sur le net. Je dois rentrer les mauvais mots clés.
 
Pourriez vous m'éclairer?
 
Merci


Message édité par jijiz le 05-06-2008 à 09:58:50
mood
Publicité
Posté le 05-06-2008 à 09:11:56  profilanswer
 

n°1741650
Taz
bisounours-codeur
Posté le 05-06-2008 à 09:25:58  profilanswer
 

man printf

n°1741664
jijiz
Posté le 05-06-2008 à 09:33:39  profilanswer
 

NAME
       printf - format and print data
 
SYNOPSIS
       printf FORMAT [ARGUMENT]...
       printf OPTION
 
DESCRIPTION
       Print ARGUMENT(s) according to FORMAT.
 
       --help display this help and exit
 
       --version
              output version information and exit
 
       FORMAT controls the output as in C printf.  Interpreted sequences are:
 
       \"     double quote
 
       \NNN   character with octal value NNN (1 to 3 digits)
 
       \\     backslash
 
       \a     alert (BEL)
 
       \b     backspace
 
       \c     produce no further output
 
       \f     form feed
 
       \n     new line
 
       \r     carriage return
 
       \t     horizontal tab
 
       \v     vertical tab
 
       \xHH   byte with hexadecimal value HH (1 to 2 digits)
 
       \uHHHH Unicode (ISO/IEC 10646) character with hex value HHHH (4 digits)
 
       \UHHHHHHHH
              Unicode character with hex value HHHHHHHH (8 digits)
 
       \t     horizontal tab
 
       \v     vertical tab
 
       \xHH   byte with hexadecimal value HH (1 to 2 digits)
 
       \uHHHH Unicode (ISO/IEC 10646) character with hex value HHHH (4 digits)
 
       \UHHHHHHHH
              Unicode character with hex value HHHHHHHH (8 digits)
 
       %%     a single %
 
       %b     ARGUMENT as a string with ‘\' escapes interpreted,
 
              except that octal escapes are of the form \0 or \0NNN
 
       and all C format specifications ending with one of diouxXfeEgGcs,  with
       ARGUMENTs converted to proper type first.  Variable widths are handled.
 
       NOTE: your shell may have its own  version  of  printf,  which  usually
       supersedes  the  version  described here.  Please refer to your shell's
       documentation for details about the options it supports.
 
AUTHOR
       Written by David MacKenzie.
 
REPORTING BUGS
       Report bugs to <bug-coreutils@gnu.org>.
 
COPYRIGHT
       Copyright © 2006 Free Software Foundation, Inc.
       This is free software.  You may redistribute copies  of  it  under  the
       terms       of       the      GNU      General      Public      License
       <http://www.gnu.org/licenses/gpl.html>.  There is NO WARRANTY,  to  the
       extent permitted by law.
 
SEE ALSO
       The  full  documentation  for printf is maintained as a Texinfo manual.
       If the info and printf programs are properly installed  at  your  site,
       the command
 
              info printf
 
       should give you access to the complete manual.
 
printf 5.97                      October 2006                        PRINTF(1)


 
C'est où??
 
J'ai testé info printf il y a 30 pages...

n°1741676
Taz
bisounours-codeur
Posté le 05-06-2008 à 09:39:01  profilanswer
 

man 3 printf

n°1741685
jijiz
Posté le 05-06-2008 à 09:46:50  profilanswer
 

Merci, peux tu m'expliquer a quoi correspond le parametre 3? stp.
 
Edit : j'ai une seconde question, je calcule divers coefficients de regression lineaire. Je dois ensuite en faire la moyenne et multiplier ces moyennes. Bref je me retrouve avec ce genre de nombre :
 
printf("%.100f",chiffr);
0.9999957084655761718750000000000000000000000000000000000000000000000000000000000000000000000000000000
 
Est-il possible que le langage c rajoute des chiffres erronés dans les décimales qui n'appartienent pas au calcul? Ou est-ce qu'il se débrouille pour ne pas introduire de chiffre superflus?
 
Si je fais :  
 
    a = 0.3232*2;
    printf("%.100F\n",a);
 
a contient 0.6463999748229980468750000000000000000000000000000000000000000000000000000000000000000000000000000000 Hmmm comment éviter ceci?


Message édité par jijiz le 05-06-2008 à 09:57:54
n°1741738
Joel F
Real men use unique_ptr
Posté le 05-06-2008 à 10:27:40  profilanswer
 
n°1741742
jijiz
Posté le 05-06-2008 à 10:32:09  profilanswer
 


ok je vais lire ceci. Si la précision n'est pas infinie, un tronquage ne me dérange pas, cependant des chiffres apparaissant comme par magie me pose probleme.

n°1741751
Joel F
Real men use unique_ptr
Posté le 05-06-2008 à 10:42:25  profilanswer
 

bah en gros float ca doit etre 8 chiffres signifcatifs. Quadn tu lui demandes d'en afficher, il affiche ce qu'il peut et il remplit le reste de 0

n°1741753
Taz
bisounours-codeur
Posté le 05-06-2008 à 10:44:43  profilanswer
 

Voir le papier justement. Les IEEE sont codés en binaire selon une certaine méthode. Donc ça "tronque" très peu souvent d'une manière plaisante en base 10. La représentation est la meilleure possible.

n°1741765
Taz
bisounours-codeur
Posté le 05-06-2008 à 11:01:15  profilanswer
 

Je me pose une question par rapport à perl qui représente tout en double par défaut. Quel est le plus grand intervalle d'entiers, avec x et y appartenant à cet intervalle, dans lequel double(x) OP double(y) est exacte ?

mood
Publicité
Posté le 05-06-2008 à 11:01:15  profilanswer
 

n°1741784
Joel F
Real men use unique_ptr
Posté le 05-06-2008 à 11:16:43  profilanswer
 

c'est une exemple du papier de tête. Je l'ai aussi fait faire en TP d'architecture, faut que je le retrouve


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  C

  Format et précision d'un float (google n'est pas mon amis). Debutant

 

Sujets relatifs
Problème de format de date SQLSoap google search api
Récupération données Google AnalyticsFormat date US-FR
[JAVA] GUI, listener et events (debutant)[ActionScript] Problème de débutant avec une variable de fonction
Génération image au format PDF Haute Def CMJNIndexation Google
Format des variables sous VBQue faire quand un site disparaît des résultats Google?
Plus de sujets relatifs à : Format et précision d'un float (google n'est pas mon amis). Debutant


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR