machine epsilon

• 09-23-2008, 05:59 PM
rosh72851
machine epsilon2
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?
• 09-23-2008, 07:09 PM
Norm
have you tried writing a program to test this?
If not, do.

Are you using float to mean the java float type?

What is the smallest number that a float can hold?
What is the smallest number that a double can hold?
• 09-23-2008, 07:23 PM
rosh72851
For IEEE754 single precision 24 dgits, which include 7 decimals. (float)
For IEEE754 double precision 53 digits, which include 15 decimal places (double)

I have a program that achieves this formula 1.0 + epsilon ==1.0
i.e. epsilon is a biggest small number that is not big enough to change 1.0.
• 09-23-2008, 09:29 PM
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.
• 09-23-2008, 10:19 PM
Norm
Quote:

how do I convert float and double data types to binary
Everything in a computer is in binary. What format are you looking for? A String of "0"s and "1"s? or what?
Quote:

answer doesnt seem to be right.
What does the output look like? Please post it.
Quote:

1.0 + epsilon ==1.0
Can you post the code that demos this?
• 09-23-2008, 10:31 PM
rosh72851
Quote:

Everything in a computer is in binary. What format are you looking for? A String of "0"s and "1"s? or what?
Well obviously a string is the easiest way.

Quote:

What does the output look like? Please post it.
If I input a value 1. The result I get is
Code:

`111111100000000000000000000000`
Ive already solved the epsilon problem.
• 09-23-2008, 10:34 PM
rosh72851
Going over the internet I can get ways only how to convert integers and not decimals (floats). If you could tell me how it works in real time, I can work on it myself.
• 09-24-2008, 12:14 AM
Norm
If you just want to see the internal values of various variables you could use the DataOutputStream. It has methods to output different types.
Either write to a disk file or use a ByteArray to hold the output.
Quote:

111111100000000000000000000000
Why do you think that value is wrong? It looks like it has enough bits.
The internal format for floats must be documented in many places online.
• 09-24-2008, 12:33 AM
rosh72851
Quote:

111111100000000000000000000000
This definitely is not the binary for integer 1.
• 09-24-2008, 03:16 AM
Norm
It's floating point not int.
Do some research on how floating point is represented on a computer.