Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

public class SubnormalFloatCreator {

private static final int MIN_EXPONENT = -126; // For IEEE-754 single precision
private static final int SIGNIFICAND_WIDTH = 23; // Number of bits in the
significand

public static float createSubnormal(int exp) {


if (exp >= MIN_EXPONENT) {
// Return a power of two float (this function needs to be implemented)
return powerOfTwoF(exp);
} else {
// Calculate how much we need to shift 1 within the bounds of an int
int shift = exp - (MIN_EXPONENT - (SIGNIFICAND_WIDTH - 1));
shift = Math.max(0, Math.min(shift, 31));

// Create the subnormal number as close as possible within int bounds


int bits = 1 << shift;
float result = bits * (float)Math.pow(2, MIN_EXPONENT -
SIGNIFICAND_WIDTH);

return result;
}
}

// Example usage
public static void main(String[] args) {
int exp = -130; // Example exponent
float result = createSubnormal(exp);
System.out.println("Subnormal float for exp " + exp + " is: " + result);
}
}
**********************************************************************************

angle0 = 0.7853981633974483f;
float angle1 = 0.46364760900080615f;
float angle2 = 0.24497866312686414f;
float angle3 = 0.12435499454676144f;
float angle4 = 0.06241880999595735f ;
float angle5 = 0.031239833430268277f;
float angle6 = 0.015623728620476831f;
float angle7 = 0.007812341060101111f;
float angle8 = 0.0039062301319669718f;
float angle9 = 0.0019531225164788188f;
float angle10 = 0.0009765621895593195f;
float angle11 = 0.0004882812111948983f;
float angle12 = 0.00024414062014936177f;
float angle13 = 0.00012207031189367021f;
float angle14 = 6.103515617420877e-05f;
float angle15 = 3.0517578115526096e-05f;
float angle16 = 1.5258789061315762e-05f;
float angle17 = 7.62939453110197e-06f;
float angle18 = 3.814697265606496e-06f;
float angle19 = 1.907348632810187e-06f;
float angle20 = 9.536743164059608e-07f;
float angle21 = 4.7683715820308884e-07f;
float angle22 = 2.3841857910155797e-07f;
float angle23 = 1.1920928955078068e-07f;
float angle24 = 5.960464477539055e-08f;
float angle25 = 2.9802322387695303e-08f;
float angle26 = 1.4901161193847655e-08f;
float angle27 = 7.450580596923828e-09f;
float angle28 = 3.725290298461914e-09f;
float angle29 = 1.862645149230957e-09f;

You might also like