Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #24049 > unrolled thread

floor()

Started byAndre <pas.mois@ailleur.be>
First post2012-08-01 14:34 +0200
Last post2012-08-03 21:11 -0400
Articles 20 on this page of 28 — 14 participants

Back to article view | Back to comp.lang.c


Contents

  floor() Andre <pas.mois@ailleur.be> - 2012-08-01 14:34 +0200
    Re: floor() Xavier Roche <xroche@free.fr.NOSPAM.invalid> - 2012-08-01 14:38 +0200
      Re: floor() Andre <pas.mois@ailleur.be> - 2012-08-01 16:47 +0200
      Re: floor() Andre <pas.mois@ailleur.be> - 2012-08-01 17:49 +0200
        Re: floor() Ike Naar <ike@sverige.freeshell.org> - 2012-08-01 15:53 +0000
          Re: floor() falk@rahul.net (Edward A. Falk) - 2012-08-01 18:26 +0000
          Re: floor() Jorgen Grahn <grahn+nntp@snipabacken.se> - 2012-08-02 16:30 +0000
            Re: floor() Keith Thompson <kst-u@mib.org> - 2012-08-02 14:58 -0700
        Re: floor() "Heinrich Wolf" <invalid@invalid.invalid> - 2012-08-01 17:56 +0200
        Re: floor() Noob <root@127.0.0.1> - 2012-08-01 17:58 +0200
        Re: floor() Keith Thompson <kst-u@mib.org> - 2012-08-01 10:31 -0700
          Re: floor() Ben Pfaff <blp@cs.stanford.edu> - 2012-08-01 10:43 -0700
            Re: floor() James Kuyper <jameskuyper@verizon.net> - 2012-08-01 13:51 -0400
              Re: floor() Ben Pfaff <blp@cs.stanford.edu> - 2012-08-01 10:59 -0700
                Re: floor() Noob <root@127.0.0.1> - 2012-08-02 10:04 +0200
                Re: floor() Jorgen Grahn <grahn+nntp@snipabacken.se> - 2012-08-02 16:33 +0000
                Re: floor() Craig Franck <craiglfranck@gmail.com> - 2012-08-03 20:49 -0400
    Re: floor() Noob <root@127.0.0.1> - 2012-08-01 16:47 +0200
      Re: floor() Andre <pas.mois@ailleur.be> - 2012-08-01 16:48 +0200
    Re: floor() TheGunslinger <mikiesrunsbaal.sec@sbcglobal.net> - 2012-08-01 09:49 -0500
      Re: floor() Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-08-01 10:58 -0400
        Re: floor() TheGunslinger <mikiesrunsbaal.sec@sbcglobal.net> - 2012-08-01 10:02 -0500
          Re: floor() James Kuyper <jameskuyper@verizon.net> - 2012-08-01 11:10 -0400
          Re: floor() TheGunslinger <mikiesrunsbaal.sec@sbcglobal.net> - 2012-08-01 10:12 -0500
            Re: floor() pete <pfiland@mindspring.com> - 2012-08-01 12:04 -0400
            Re: floor() James Kuyper <jameskuyper@verizon.net> - 2012-08-01 12:04 -0400
            Re: floor() Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-08-01 13:07 -0400
            Re: floor() Craig Franck <craiglfranck@gmail.com> - 2012-08-03 21:11 -0400

Page 1 of 2  [1] 2  Next page →


#24049 — floor()

FromAndre <pas.mois@ailleur.be>
Date2012-08-01 14:34 +0200
Subjectfloor()
Message-ID<5019226f$0$3111$ba620e4c@news.skynet.be>
Trying to use floor in a short progrm, using gcc version 4.5.1 20100924 
(Red Hat 4.5.1-4) (GCC)
But compilation keep returning
/tmp/cca35RWE.o: In function `main':
testUTC.c:(.text+0xa8): undefined reference to `floor'
collect2: ld a retourné 1 code d'état d'exécution
Any idea where to look??
Many thanks
André
BTW: I am retired and doing somme progr for fun :-))
also using floor, extrated from same progrme works with PICC for pic16f..
CU

[toc] | [next] | [standalone]


#24050

FromXavier Roche <xroche@free.fr.NOSPAM.invalid>
Date2012-08-01 14:38 +0200
Message-ID<jvb80h$6pp$1@news.httrack.net>
In reply to#24049
On 08/01/2012 02:34 PM, Andre wrote:
> testUTC.c:(.text+0xa8): undefined reference to `floor'

This is Linux specific (not specifically related to C). You need the "m" 
library (math) on Linux.

See:
<http://www.kernel.org/doc/man-pages/online/pages/man3/floor.3.html>
"Link with -lm"

gcc ... -lm

[toc] | [prev] | [next] | [standalone]


#24055

FromAndre <pas.mois@ailleur.be>
Date2012-08-01 16:47 +0200
Message-ID<5019419a$0$3123$ba620e4c@news.skynet.be>
In reply to#24050
Le 01/08/2012 14:38, Xavier Roche a écrit :
> On 08/01/2012 02:34 PM, Andre wrote:
>> testUTC.c:(.text+0xa8): undefined reference to `floor'
>
> This is Linux specific (not specifically related to C). You need the "m"
> library (math) on Linux.
>
> See:
> <http://www.kernel.org/doc/man-pages/online/pages/man3/floor.3.html>
> "Link with -lm"
>
> gcc ... -lm
>
Many thanks
André

[toc] | [prev] | [next] | [standalone]


#24064

FromAndre <pas.mois@ailleur.be>
Date2012-08-01 17:49 +0200
Message-ID<50195010$0$3109$ba620e4c@news.skynet.be>
In reply to#24050
Le 01/08/2012 14:38, Xavier Roche a écrit :
> On 08/01/2012 02:34 PM, Andre wrote:
>> testUTC.c:(.text+0xa8): undefined reference to `floor'
>
> This is Linux specific (not specifically related to C). You need the "m"
> library (math) on Linux.
>
> See:
> <http://www.kernel.org/doc/man-pages/online/pages/man3/floor.3.html>
> "Link with -lm"
>
> gcc ... -lm
>
I must have missed something as it compile Ok but result of floor(2.233) 
is 0??

#include <stdio.h>
#include <math.h>


/**************/
main(argc,argv)
int argc;
char *argv[];
{
int UTC;
double heure;
float minute;
double rst;
int hx;

   printf("%d\n\r",floor(2.2333));


}
/*****/

  gcc testUTC.c -o heure -lm


./heure
0


[toc] | [prev] | [next] | [standalone]


#24065

FromIke Naar <ike@sverige.freeshell.org>
Date2012-08-01 15:53 +0000
Message-ID<slrn3vfsk1ik77.bn.ike@sverige.freeshell.org>
In reply to#24064
On 2012-08-01, Andre <pas.mois@ailleur.be> wrote:
> I must have missed something as it compile Ok but result of floor(2.233) 
> is 0??
>
> #include <stdio.h>
> #include <math.h>
>
> /**************/
> main(argc,argv)
> int argc;
> char *argv[];
> {
> int UTC;
> double heure;
> float minute;
> double rst;
> int hx;
>
>    printf("%d\n\r",floor(2.2333));

Type mismatch; floor returns a double, but the
"%d" format expects an integer.

> }
> /*****/

[toc] | [prev] | [next] | [standalone]


#24082

Fromfalk@rahul.net (Edward A. Falk)
Date2012-08-01 18:26 +0000
Message-ID<jvbsc9$ugp$1@blue-new.rahul.net>
In reply to#24065
In article <slrn3vfsk1ik77.bn.ike@sverige.freeshell.org>,
Ike Naar  <ike@sverige.freeshell.org> wrote:
>>
>>    printf("%d\n\r",floor(2.2333));
>
>Type mismatch; floor returns a double, but the
>"%d" format expects an integer.

Oh, and get rid of the '\r' in the format string. The
C stdio library will handle line endings correctly for
you.

-- 
	-Ed Falk, falk@despams.r.us.com
	http://thespamdiaries.blogspot.com/

[toc] | [prev] | [next] | [standalone]


#24139

FromJorgen Grahn <grahn+nntp@snipabacken.se>
Date2012-08-02 16:30 +0000
Message-ID<slrnk1lapu.ph6.grahn+nntp@frailea.sa.invalid>
In reply to#24065
On Wed, 2012-08-01, Ike Naar wrote:
> On 2012-08-01, Andre <pas.mois@ailleur.be> wrote:
>> I must have missed something as it compile Ok but result of floor(2.233) 
>> is 0??
>>
...
>>    printf("%d\n\r",floor(2.2333));
>
> Type mismatch; floor returns a double, but the
> "%d" format expects an integer.

Might as well mention this: turn on more warnings from the compiler
to avoid such errors. For gcc it's something like

  -W -Wall -pedantic -ansi -g -O2

/Jorgen

-- 
  // Jorgen Grahn <grahn@  Oo  o.   .     .
\X/     snipabacken.se>   O  o   .

[toc] | [prev] | [next] | [standalone]


#24154

FromKeith Thompson <kst-u@mib.org>
Date2012-08-02 14:58 -0700
Message-ID<lnmx2d0xec.fsf@nuthaus.mib.org>
In reply to#24139
Jorgen Grahn <grahn+nntp@snipabacken.se> writes:
> On Wed, 2012-08-01, Ike Naar wrote:
>> On 2012-08-01, Andre <pas.mois@ailleur.be> wrote:
>>> I must have missed something as it compile Ok but result of floor(2.233) 
>>> is 0??
>>>
> ...
>>>    printf("%d\n\r",floor(2.2333));
>>
>> Type mismatch; floor returns a double, but the
>> "%d" format expects an integer.
>
> Might as well mention this: turn on more warnings from the compiler
> to avoid such errors. For gcc it's something like
>
>   -W -Wall -pedantic -ansi -g -O2

-W is better written as -Wextra

-g doesn't enable warnings; it produces information to be used by a
debugger.

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
    Will write code for food.
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

[toc] | [prev] | [next] | [standalone]


#24066

From"Heinrich Wolf" <invalid@invalid.invalid>
Date2012-08-01 17:56 +0200
Message-ID<jvbjim$se6$1@news.m-online.net>
In reply to#24064
"Andre" <pas.mois@ailleur.be> schrieb im Newsbeitrag 
news:50195010$0$3109$ba620e4c@news.skynet.be...
...
> I must have missed something as it compile Ok but result of floor(2.233) 
> is 0??
>
> #include <stdio.h>
> #include <math.h>
>
>
> /**************/
> main(argc,argv)
> int argc;
> char *argv[];
> {
> int UTC;
> double heure;
> float minute;
> double rst;
> int hx;
>
>   printf("%d\n\r",floor(2.2333));

My Borland C++Builder 5 tells the prototype
double floor(double x);
So your printf has a wrong format string. You should code
printf("%1.0f\n\r",floor(2.2333));


> }
> /*****/
>
>  gcc testUTC.c -o heure -lm
>
>
> ./heure
> 0
>
>
> 

[toc] | [prev] | [next] | [standalone]


#24067

FromNoob <root@127.0.0.1>
Date2012-08-01 17:58 +0200
Message-ID<jvbjnc$6nl$1@dont-email.me>
In reply to#24064
Andre wrote:

> printf("%d\n\r",floor(2.2333));

floor returns a double, not an int.
Did you mean lrint perhaps?

> gcc testUTC.c -o heure -lm

Add -Wall -Wextra to your GCC command line.
warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘double’ [-Wformat]

Regards.

[toc] | [prev] | [next] | [standalone]


#24074

FromKeith Thompson <kst-u@mib.org>
Date2012-08-01 10:31 -0700
Message-ID<ln7gti34ei.fsf@nuthaus.mib.org>
In reply to#24064
Andre <pas.mois@ailleur.be> writes:
[...]
>    printf("%d\n\r",floor(2.2333));
[...]

Apart from the type mismatch, the "\r" is not necessary.  Printing
"\n" to a text stream will emit whatever is needed to mark the end
of a line.

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
    Will write code for food.
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

[toc] | [prev] | [next] | [standalone]


#24076

FromBen Pfaff <blp@cs.stanford.edu>
Date2012-08-01 10:43 -0700
Message-ID<871ujqpkxf.fsf@blp.benpfaff.org>
In reply to#24074
Keith Thompson <kst-u@mib.org> writes:

> Andre <pas.mois@ailleur.be> writes:
> [...]
>>    printf("%d\n\r",floor(2.2333));
> [...]
>
> Apart from the type mismatch, the "\r" is not necessary.  Printing
> "\n" to a text stream will emit whatever is needed to mark the end
> of a line.

Furthermore, when both \r and \n are used, the normal order is
\r\n (CR LF, not LF CR).

[toc] | [prev] | [next] | [standalone]


#24077

FromJames Kuyper <jameskuyper@verizon.net>
Date2012-08-01 13:51 -0400
Message-ID<jvbqaa$gtr$1@dont-email.me>
In reply to#24076
On 08/01/2012 01:43 PM, Ben Pfaff wrote:
> Keith Thompson <kst-u@mib.org> writes:
> 
>> Andre <pas.mois@ailleur.be> writes:
>> [...]
>>>    printf("%d\n\r",floor(2.2333));
>> [...]
>>
>> Apart from the type mismatch, the "\r" is not necessary.  Printing
>> "\n" to a text stream will emit whatever is needed to mark the end
>> of a line.
> 
> Furthermore, when both \r and \n are used, the normal order is
> \r\n (CR LF, not LF CR).

According to <http://en.wikipedia.org/wiki/Newline>, LF+CR is used for
"Acorn BBC and RISC OS spooled text output".

[toc] | [prev] | [next] | [standalone]


#24079

FromBen Pfaff <blp@cs.stanford.edu>
Date2012-08-01 10:59 -0700
Message-ID<87wr1io5n3.fsf@blp.benpfaff.org>
In reply to#24077
James Kuyper <jameskuyper@verizon.net> writes:

> On 08/01/2012 01:43 PM, Ben Pfaff wrote:
>> Keith Thompson <kst-u@mib.org> writes:
>> 
>>> Andre <pas.mois@ailleur.be> writes:
>>> [...]
>>>>    printf("%d\n\r",floor(2.2333));
>>> [...]
>>>
>>> Apart from the type mismatch, the "\r" is not necessary.  Printing
>>> "\n" to a text stream will emit whatever is needed to mark the end
>>> of a line.
>> 
>> Furthermore, when both \r and \n are used, the normal order is
>> \r\n (CR LF, not LF CR).
>
> According to <http://en.wikipedia.org/wiki/Newline>, LF+CR is used for
> "Acorn BBC and RISC OS spooled text output".

I stand by my claim about "normal" order.  I admit that there may
be systems that use an abnormal order.

[toc] | [prev] | [next] | [standalone]


#24114

FromNoob <root@127.0.0.1>
Date2012-08-02 10:04 +0200
Message-ID<jvdc9v$f0g$1@dont-email.me>
In reply to#24079
Ben Pfaff wrote:

> I stand by my claim about "normal" order.  I admit that there may
> be systems that use an abnormal order.

The problem with "norms" is that they are moving targets ;-)

[toc] | [prev] | [next] | [standalone]


#24140

FromJorgen Grahn <grahn+nntp@snipabacken.se>
Date2012-08-02 16:33 +0000
Message-ID<slrnk1lauk.ph6.grahn+nntp@frailea.sa.invalid>
In reply to#24079
On Wed, 2012-08-01, Ben Pfaff wrote:
> James Kuyper <jameskuyper@verizon.net> writes:
>
>> On 08/01/2012 01:43 PM, Ben Pfaff wrote:
...
>>> Furthermore, when both \r and \n are used, the normal order is
>>> \r\n (CR LF, not LF CR).
>>
>> According to <http://en.wikipedia.org/wiki/Newline>, LF+CR is used for
>> "Acorn BBC and RISC OS spooled text output".
>
> I stand by my claim about "normal" order.  I admit that there may
> be systems that use an abnormal order.

Or /have been/ in this case. I haven't heard about Acorn for 20 years.

/Jorgen

-- 
  // Jorgen Grahn <grahn@  Oo  o.   .     .
\X/     snipabacken.se>   O  o   .

[toc] | [prev] | [next] | [standalone]


#24184

FromCraig Franck <craiglfranck@gmail.com>
Date2012-08-03 20:49 -0400
Message-ID<mYWdnVA14Y827IHNnZ2dnUVZ_o6dnZ2d@giganews.com>
In reply to#24079
On 8/1/2012 1:59 PM, Ben Pfaff wrote:
> James Kuyper <jameskuyper@verizon.net> writes:
>
>> On 08/01/2012 01:43 PM, Ben Pfaff wrote:
>>> Keith Thompson <kst-u@mib.org> writes:
>>>
>>>> Andre <pas.mois@ailleur.be> writes:
>>>> [...]
>>>>>     printf("%d\n\r",floor(2.2333));
>>>> [...]
>>>>
>>>> Apart from the type mismatch, the "\r" is not necessary.  Printing
>>>> "\n" to a text stream will emit whatever is needed to mark the end
>>>> of a line.
>>>
>>> Furthermore, when both \r and \n are used, the normal order is
>>> \r\n (CR LF, not LF CR).
>>
>> According to <http://en.wikipedia.org/wiki/Newline>, LF+CR is used for
>> "Acorn BBC and RISC OS spooled text output".
>
> I stand by my claim about "normal" order.  I admit that there may
> be systems that use an abnormal order.

CR LF does have the virtue that on DECwriter technology it may
have been less likely to cause a jam.

Craig

[toc] | [prev] | [next] | [standalone]


#24054

FromNoob <root@127.0.0.1>
Date2012-08-01 16:47 +0200
Message-ID<jvbfgq$bjo$1@dont-email.me>
In reply to#24049
Andre wrote:
> Trying to use floor in a short progrm, using gcc version 4.5.1
> 20100924 (Red Hat 4.5.1-4) (GCC) But compilation keep returning
> /tmp/cca35RWE.o: In function `main': testUTC.c:(.text+0xa8):
> undefined reference to `floor'

cf. comp.lang.c FAQ list
Question 14.3
http://c-faq.com/fp/libm.html

Q: I'm trying to do some simple trig, and I am #including <math.h>,
but the linker keeps complaining that functions like sin and cos are
undefined.

A: Make sure you're actually linking with the math library. For
instance, due to a longstanding bug in Unix and Linux systems, you
usually need to use an explicit -lm flag, at the end of the command
line, when compiling/linking.

[toc] | [prev] | [next] | [standalone]


#24056

FromAndre <pas.mois@ailleur.be>
Date2012-08-01 16:48 +0200
Message-ID<501941cd$0$3123$ba620e4c@news.skynet.be>
In reply to#24054
Le 01/08/2012 16:47, Noob a écrit :
> Andre wrote:
>> Trying to use floor in a short progrm, using gcc version 4.5.1
>> 20100924 (Red Hat 4.5.1-4) (GCC) But compilation keep returning
>> /tmp/cca35RWE.o: In function `main': testUTC.c:(.text+0xa8):
>> undefined reference to `floor'
>
> cf. comp.lang.c FAQ list
> Question 14.3
> http://c-faq.com/fp/libm.html
>
> Q: I'm trying to do some simple trig, and I am #including<math.h>,
> but the linker keeps complaining that functions like sin and cos are
> undefined.
>
> A: Make sure you're actually linking with the math library. For
> instance, due to a longstanding bug in Unix and Linux systems, you
> usually need to use an explicit -lm flag, at the end of the command
> line, when compiling/linking.
many thanks
André

[toc] | [prev] | [next] | [standalone]


#24057

FromTheGunslinger <mikiesrunsbaal.sec@sbcglobal.net>
Date2012-08-01 09:49 -0500
Message-ID<i4gi18pcga6nps7u4duc364qjsc00td4te@4ax.com>
In reply to#24049
On Wed, 01 Aug 2012 14:34:55 +0200, Andre <pas.mois@ailleur.be> wrote:

>Trying to use floor in a short progrm, using gcc version 4.5.1 20100924 
>(Red Hat 4.5.1-4) (GCC)
>But compilation keep returning
>/tmp/cca35RWE.o: In function `main':
>testUTC.c:(.text+0xa8): undefined reference to `floor'
>collect2: ld a retourné 1 code d'état d'exécution
>Any idea where to look??
>Many thanks
>André
>BTW: I am retired and doing somme progr for fun :-))
>also using floor, extrated from same progrme works with PICC for pic16f..
>CU

I am assuming you are unfamiliar with some of the libraries.

I would suggest a Google search on: C STL floor function

There are several really excellent websites having info on the C STL
libraries.

You will probably want to bookmark a few for future reference.

Here is a URL to answer your question:

http://www.cprogramming.com/fod/floor.html

I am guessing you haven't added this library which defines the floor
function:

#include <cmath>

Respectfully,

MJR

[toc] | [prev] | [next] | [standalone]


Page 1 of 2  [1] 2  Next page →

Back to top | Article view | comp.lang.c


csiph-web