Thread: Floating point problem

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Jul 2007
    Posts
    9

    Floating point problem

    hey i am a complete newbie to c.


    I am having this problem with floating points and the output is producing really wired results
    I'm using gcc to compile it

    Code:
    float i=0.0;
    for(;i<=20.0;i+=0.1)
    {
    if(i==0.0 || ((int)(i*10))&#37;10==0)
    {
    printf("\n");
    printf("%5.1f ",i);
    }
    
    printf("%5.2f ",sqrt(i));
    }
    the above code is to print a table of square roots in a sort of tabled layout.
    when we start it prints 0.0 and print the list of sqrt from 0.1 to 0.9
    when 1.0 it again goes to a new line prints 1.0 as well as the sqrts from 1.0 to 1.9
    but it creates a problem in 3.0 in my machine for some reason. Please try it out.
    It's really strange

    Regards
    Last edited by greenberet; 07-13-2007 at 08:29 AM. Reason: debugging changed the code a little

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. For the numerical recipes in C types!
    By Smattacus in forum C Programming
    Replies: 5
    Last Post: 10-28-2008, 07:57 PM
  2. String and Floating Point Conversion Help
    By dfghjk in forum C++ Programming
    Replies: 14
    Last Post: 05-04-2008, 12:11 PM
  3. Floating point checking problem
    By ikkiutsu in forum C Programming
    Replies: 8
    Last Post: 12-03-2003, 06:35 AM
  4. Floating point faster than fixed-point
    By VirtualAce in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 11-08-2001, 11:34 PM