Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- Italy
- France
- history
- Book
- Book review
- hbase
- Linux
- comic agile
- ubuntu
- agile
- Programming
- psychology
- hadoop
- web
- leadership
- essay
- MySQL
- program
- programming_book
- django
- Spain
- management
- RFID
- Python
- Software Engineering
- Kuala Lumpur
- Malaysia
- QT
- Java
- erlang
Archives
- Today
- Total
Java reals IEEE754 본문
http://people.uncw.edu/tompkinsj/133/numbers/Reals.htm
float
| 1bit sign | 8 bit exponent | 23 bit mantissa |
double
| 1bit sign | 11 bit exponent | 52 bit mantissa |
sign: 0 + 1 -
exponent: exponent - 127 for float, exponent - 1023 for double
mantissa: normalized 1-plus fraction
print bits of 1.0D 00111111 11110000 00000000 00000000 00000000 00000000 00000000 00000000
(0000 00000000 00000000 00000000 00000000 00000000 00000000 + 1) * 2 ^ (0111111 1111 - 1023) = 1.0
float
| 1bit sign | 8 bit exponent | 23 bit mantissa |
double
| 1bit sign | 11 bit exponent | 52 bit mantissa |
sign: 0 + 1 -
exponent: exponent - 127 for float, exponent - 1023 for double
mantissa: normalized 1-plus fraction
print bits of 1.0D 00111111 11110000 00000000 00000000 00000000 00000000 00000000 00000000
(0000 00000000 00000000 00000000 00000000 00000000 00000000 + 1) * 2 ^ (0111111 1111 - 1023) = 1.0
public class TestIEEE754 { public static void printBits(final long l) { for ( int i = 63; i >= 0; --i ) { final long bit = 0x1L << i; System.out.print((l & bit) != 0 ? "1" : "0"); if ( 0 == i % 8 ) System.out.print(" "); } System.out.println(); } // http://people.uncw.edu/tompkinsj/133/numbers/Reals.htm public static void main(final String[] args) { final long l = 1L; System.out.println("Double.longBitsToDouble(" + l + ")\t" + Double.longBitsToDouble(l)); System.out.print("print bits of " + l + "L\t"); printBits(l); System.out.println("Double.longBitsToDouble(" + l + ")\t" + Double.longBitsToDouble(l)); final double d = 1.0D; System.out.println("\nDouble.toHexString(" + d + ")\t" + Double.toHexString(d)); System.out.println("Double.doubleToLongBits(" + d + ")\t" + Double.doubleToLongBits(d)); System.out.print("print bits of " + d + "D\t"); printBits(Double.doubleToLongBits(d)); System.out.println("Double.doubleToRawLongBits(" + d + ")\t" + Double.doubleToRawLongBits(d)); System.out.print("print bits of " + d + "D\t"); printBits(Double.doubleToRawLongBits(d)); } }
Comments