ºìÁªLinuxÃÅ»§
Linux°ïÖú

¸¡µãÐÍ£¨Floating-Point Types£©

·¢²¼Ê±¼ä:2006-05-03 15:12:01À´Ô´:ºìÁª×÷Õß:reing
¸¡µãÊý×Ö£¬Ò²¾ÍÊÇÈËÃÇÖªµÀµÄʵÊý£¨real£©£¬µ±¼ÆËãµÄ±í´ïʽÓÈÒªÇóʱ±»Ê¹Óá£ÀýÈ磬¼ÆËãƽ·½¸ù£¬»ò³¬³öÈËÀྭÑéµÄ¼ÆËãÈçÕýÏÒºÍÓàÏÒ£¬ËüÃǵļÆËã½á¹ûµÄ¾«¶ÈÒªÇóʹÓø¡µãÐÍ¡£Java ʵÏÖÁ˱ê×¼£¨IEEE-754 £©µÄ¸¡µãÐͺÍÔËËã·û¼¯¡£ÓÐ2ÖÖ¸¡µãÐÍ£¬µ¥¾«¶È¸¡µãÐÍ£¨float £©¼°Ë«¾«¶È£¨double £©¸¡µãÐÍ¡£

ËûÃǵij¤¶ÈºÍ±ä»¯·¶Î§Èç±í3-2 Ëùʾ£º

±í3-2 ¸¡µãÐÍ·ÖÀ༰ÆäÌØÐÔ

Ãû³Æ λÊý ÊýµÄ·¶Î§
DOUBLE 64 1.7E-308¡«1.7E+308
float 32 3.4E-038¡«3.4E+038

ÏÂÃæÌÖÂÛ¸¡µãÐ͵ÄÿһÖÖÀàÐÍ¡£

3.4.1 µ¥¾«¶È¸¡µãÐÍ£¨float£©

µ¥¾«¶È¸¡µãÐÍ£¨float £©×¨Ö¸Õ¼ÓÃ32λ´æ´¢¿Õ¼äµÄµ¥¾«¶È£¨single-precision £©Öµ¡£µ¥¾«¶ÈÔÚһЩ´¦ÀíÆ÷ÉϱÈË«¾«¶È¸ü¿ì¶øÇÒÖ»Õ¼ÓÃË«¾«¶ÈÒ»°ëµÄ¿Õ¼ä£¬µ«Êǵ±ÖµºÜ´ó»òºÜСµÄʱºò£¬Ëü½«±äµÃ²»¾«È·¡£µ±ÄãÐèҪСÊý²¿·Ö²¢ÇÒ¶Ô¾«¶ÈµÄÒªÇ󲻸ßʱ£¬µ¥¾«¶È¸¡µãÐ͵ıäÁ¿ÊÇÓÐÓõġ£ÀýÈ磬µ±±íʾÃÀÔªºÍ·Öʱ£¬µ¥¾«¶È¸¡µãÐÍÊÇÓÐÓõġ£

ÕâÊÇһЩÉùÃ÷µ¥¾«¶È¸¡µãÐͱäÁ¿µÄÀý×Ó£ºfloat hightemp£¬lowtemp;
3.4.2 Ë«¾«¶ÈÐÍ£¨double £©¸¡µãÐÍ

Ë«¾«¶ÈÐÍ£¬ÕýÈçËüµÄ¹Ø¼ü×Ö¡°double ¡±±íʾµÄ£¬Õ¼ÓÃ64λµÄ´æ´¢¿Õ¼ä¡£ÔÚһЩÏÖ´úµÄ±»ÓÅ»¯ÓÃÀ´½øÐиßËÙÊýѧ¼ÆËãµÄ´¦ÀíÆ÷ÉÏË«¾«¶ÈÐÍʵ¼ÊÉϱȵ¥¾«¶ÈµÄ¿ì¡£ËùÓг¬³öÈËÀྭÑéµÄÊýѧº¯Êý£¬Èçsin ( )£¬cos( ) £¬ºÍsqrt( )¾ù·µ»ØË«¾«¶ÈµÄÖµ¡£µ±ÄãÐèÒª±£³Ö¶à´Î·´¸´µü´úµÄ¼ÆËãµÄ¾«È·ÐÔʱ£¬»òÔÚ²Ù×÷ÖµºÜ´óµÄÊý×Öʱ£¬Ë«¾«¶ÈÐÍÊÇ×îºÃµÄÑ¡Ôñ¡£

ÏÂÃæµÄ¶Ì³ÌÐòÓÃË«¾«¶È¸¡µãÐͱäÁ¿¼ÆËãÒ»¸öÔ²µÄÃæ»ý£º

// Compute the area of a circle.class Area {public static void main(String args[]) { double pi£¬r£¬a;

r = 10.8; // radius of circlepi = 3.1416; // pi£¬approximatelya = pi * r * r; // compute areaSystem.out.println("Area of circle is " + a);

}
}
ÎÄÕÂÆÀÂÛ

¹²ÓÐ 0 ÌõÆÀÂÛ