représentation des réel simple p récision

parsy jean-pierre <[email protected]>
Newsgroups gmane.comp.lang.ada.france
Message-ID <[email protected]>
Le format de réels est expliqué dans la doc java

http://java.sun.com/j2se/1.4.2/docs/api/

dans les classes Float et Double du paquetage
java.lang

La classe Float comporte les méthodes :

static float intBitsToFloat(int bits)

   Returns the float value corresponding to a given
bit represention.

static int 	floatToRawIntBits(float value)
   Returns a representation of the specified
floating-point
   value according to the IEEE 754 floating-point 
   "single format" bit layout, 
   preserving Not-a-Number (NaN) values.
------------------------------------------   
Un float (réel simple) peut se normaliser sous la
forme
     s * m * 2^e 
avec la mantisse  1<=m<2 

Par exemple 10 s'écrit en binaire 1010 on obtient
après 
normalisation 1.010*2^3

Après cette opération de normalisation, le bit de
poids fort est toujours à 1, pour gagner de la place
il n'est pas stocké.

Un float (réel simple) est codé sur 4 octets
bit  31      s
bits 30-23   e + 0x7f
bits 22-0    m ( sans le bit m-1)

Reprenons notre exemple
s = 0
e+0x7f = 1000 0010
m      = 0100...

soit 
0100 0010 0010 0000 0000 0000 0000 0000
-----------------
Pour 1
s=0 m=1 e=0
e+0x7f=0111 1111
m=0...

0011 1111 1000 0000 0000 0000
--------------------
Pour 0.5
s=0 m=1 e=-1
e+0x7f=0111 1110
m=0...

0011 1111 0000 0000 0000 0000
------------------------
Pour 0.1 en hexa 0.19999...
en binaire 0.00011001100110011001...
après normalisation
1.1001100110011001 * 2-4
s=0
e+0x7f=0111 1011
m =1001 1001 1001

0011 1101 1100 1100 1100 1100 1100 1101 ( arrondi)

Une suite pour les doubles demain






	

	
		
___________________________________________________________________________ 
Appel audio GRATUIT partout dans le monde avec le nouveau Yahoo! Messenger 
Téléchargez cette version sur http://fr.messenger.yahoo.com
_______________________________________________
Site WWW de l'association Ada-France: http://www.ada-france.org/
[email protected]
http://www.ada-france.org/mailman/listinfo/ada-france
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.