Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

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

  1. #1
    Junior Member
    Join Date
    Sep 2008
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation 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?
    Last edited by rosh72851; September 23rd, 2008 at 05:00 PM.


  2. #2
    Junior Member
    Join Date
    Sep 2008
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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
    Integer.toBinaryString(Float.floatToRawIntBits(value));

    But the answer doesnt seem to be right.
    Please suggest.

  3. #3
    Junior Member
    Join Date
    Sep 2008
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: machine epsilon

    Anybody. I just need to know to convert a float into binary. Not the code.

  4. #4
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: machine epsilon

    Quote Originally Posted by rosh72851 View Post
    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
    Integer.toBinaryString(Float.floatToRawIntBits(value));

    But the answer doesnt seem to be right.
    Please suggest.
    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)()
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  5. #5
    Junior Member
    Join Date
    Sep 2008
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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.

  6. #6
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: machine epsilon

    This is how to convert int to Binary:

    public class Class1 {
     
     public static void main(String[] args) {
     
      int myInt = 1;
      System.out.println(Integer.toBinaryString(myInt));
     }
    }
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  7. #7
    Forum old-timer
    Join Date
    Nov 2008
    Location
    Faversham, Kent, UK
    Posts
    472
    My Mood
    Mellow
    Thanks
    4
    Thanked 58 Times in 54 Posts

    Default Re: machine epsilon

    Quote Originally Posted by rosh72851 View Post
    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.

Similar Threads

  1. Java error "could not create java virtual machine"
    By aubrey4444 in forum Java Theory & Questions
    Replies: 17
    Last Post: October 3rd, 2010, 12:51 PM
  2. Moving MySql Database from one machine to another machine
    By vaishali in forum JDBC & Databases
    Replies: 5
    Last Post: July 21st, 2010, 01:21 AM
  3. need help with Vending Machine code...
    By mia_tech in forum Loops & Control Statements
    Replies: 3
    Last Post: April 20th, 2009, 05:24 AM
  4. Replies: 8
    Last Post: February 24th, 2009, 04:04 PM