# What would be the smallest positive float (epsilon) such that 1.0 + epsilon != 1.0f?

• September 23rd, 2008, 10:55 AM
rosh72851
What would be the smallest positive float (epsilon) such that 1.0 + epsilon != 1.0f?
What would be the smallest positive float (epsilon) such that 1.0 + epsilon != 1.0f?
What is the condition that I have to use to attain this?
• September 23rd, 2008, 02:29 PM
rosh72851
Re: machine epsilon
Ok I figured how to do that.

Next question, how do I convert float and double data types to binary. For float, ive used the function
Code :

`Integer.toBinaryString(Float.floatToRawIntBits(value));`

But the answer doesnt seem to be right.
• September 23rd, 2008, 03:50 PM
rosh72851
Re: machine epsilon
Anybody. I just need to know to convert a float into binary. Not the code.
• September 23rd, 2008, 04:17 PM
JavaPF
Re: machine epsilon
Quote:

Originally Posted by rosh72851
Ok I figured how to do that.

Next question, how do I convert float and double data types to binary. For float, ive used the function
Code :

`Integer.toBinaryString(Float.floatToRawIntBits(value));`

But the answer doesnt seem to be right.

The above code is what you need to convert a float to binary. I'm not sure why this is not working for you?

Also, take a look at:

Float.parseFloat]Float (Java 2 Platform SE v1.4.2)()
• September 23rd, 2008, 04:22 PM
rosh72851
Re: machine epsilon
If I input a value of 1 into the function: Integer.toBinaryString(Float.floatToRawIntBits(val ue));

I get the solution as 111111100000000000000000000000. which is definitely wrong.

If someone can tell me manually how to convert a decimal number into a decimal binary, I can manually code it.
• September 23rd, 2008, 07:37 PM
JavaPF
Re: machine epsilon
This is how to convert int to Binary:

Code :

```public class Class1 {   public static void main(String[] args) {   int myInt = 1; System.out.println(Integer.toBinaryString(myInt)); } }```
• November 14th, 2008, 02:09 PM
dlorde
Re: machine epsilon
Quote:

Originally Posted by rosh72851
But the answer doesnt seem to be right.

What makes you think so? What should it look like?

A Java float is a single-precision 32-bit format IEEE 754 value (see IEEE Standard for Binary Floating-Point Arithmetic, ANSI/IEEE Standard 754-1985). That's probably what you're seeing.