Thread: floor

  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    75

    floor

    Hi,

    what's the floor function in C?
    I tried floor() it did not work.

  2. #2
    Registered User
    Join Date
    Oct 2008
    Posts
    75
    I did not forget : #include <math.h>

    I get: undefined reference to `floor'

  3. #3
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    floor() is part of math.h. If gcc is your compiler, you also need to use -lm to link to the math library. Then you can use, eg. "float x=floor(3.7f);"

    ps, C rounds down by default, so "int x=3.7" means x==3
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  4. #4
    Registered User
    Join Date
    Oct 2008
    Posts
    75
    thanks MK27

    -lm was the problem

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. floor() problems
    By swgh in forum C++ Programming
    Replies: 6
    Last Post: 06-06-2008, 08:42 AM
  2. Elevator Function confusion
    By applescruff in forum C++ Programming
    Replies: 5
    Last Post: 12-16-2004, 10:14 AM
  3. floor & floorf
    By chrismiceli in forum C Programming
    Replies: 1
    Last Post: 08-09-2003, 10:58 PM
  4. Problem using floor() function
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 05-02-2002, 04:15 PM
  5. Newbie working on a lift simulation
    By dethray79 in forum C++ Programming
    Replies: 1
    Last Post: 10-07-2001, 08:28 AM