/**
 * This program shows how you can convert a +ve 'int' to a float
 * by only using bit operations.
 */

/**
 * @author silviabreu
 *
 */
public class MyFlt {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		double d = 4.0 * 1024 * 1024 * 1024 * 1024 * 1024;
		System.out.printf("d = %.3f\n", d);
		long msb = 0xffffffff00000000L;
		long lsb = 0x00000000ffffffffL;
		long l = Double.doubleToLongBits(d);
		l = (l & msb) | ((l+1) & lsb);
		d = Double.longBitsToDouble(l);
		System.out.printf("d (+1 in lsb) = %.3f\n", d);
		// now put 42 in lsbits, and subtract the 2^52 again
		l = (l & msb) | (42L & lsb);
		d = Double.longBitsToDouble(l);
		d -= 4.0 * 1024 * 1024 * 1024 * 1024 * 1024;
		System.out.printf("d (should now be 42) = %.3f\n", d);
	}

}