user5182503
user5182503

Reputation:

Position of point in mantissa

I am trying to understand how java works with floating point. As I understand there must be sign,exponent and mantissa in 32 bits (float). However, I can't understand how java defines the decimal part in mantissa. As I understand mantissa can be from 0,.... till 9,......

The question is how java defines where is position of point. Could anyone explain?

Upvotes: 0

Views: 318

Answers (1)

Peter Lawrey
Peter Lawrey

Reputation: 533680

Java doesn't define how float works, IEEE does.

float is a binary format so the possible range of the 24-bit mantissa for normal numbers is

0b1.0000 0000 0000 0000 0000 0000

to

0b1.1111 1111 1111 1111 1111 1111

This represents 1.0 to 2.0 - 1/2^24

For normal numbers the mantissa always starts with a 1 so it is not actually stored. This is because the values is

sign * 2^exp * mantissa.

The exp is adjusted so the mantissa starts 1. There are also sub-normal numbers which don't do this, but this only applies to very small numbers.

If you want to see how a float is represented you can have a look at

int i = Float.floatToRawIntBits(1.5);

The i will have the 32-bit value which represents the float

Upvotes: 3

Related Questions