LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-29-2005, 03:10 PM   #16
kjordan
Member
 
Registered: Jul 2004
Distribution: LFS, I felt the itch and scratched it
Posts: 227

Rep: Reputation: 31

Seems I was even outdated, it's up to 2.08 and the definition is fixed:
Quote:
SYNOPSIS
#include <math.h>

double log2(double x);
float log2f(float x);
long double log2l(long double x);

Compile with -std=c99; link with -lm.

DESCRIPTION
The log2() function returns the base 2 logarithm of x.

ERRORS
The log2() function can return the following error:

EDOM The argument x is negative.

ERANGE The argument x is zero. The log of zero is not defined (minus
infinity).

CONFORMING TO
SVID 3, POSIX, 4.3BSD, ISO 9899. The float and the long double vari-
ants are C99 requirements.
 
Old 09-29-2005, 05:08 PM   #17
PTrenholme
Senior Member
 
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 4,186

Rep: Reputation: 347Reputation: 347Reputation: 347Reputation: 347
Quote:
Originally posted by Dark_Helmet
Interesting point. I'm guessing that may be a copy-paste error in the man page.
[snip]
Yes, I, too, think it's an error in the manual. I get
Code:
$ c99 -lm -o test test.c

$ ./test 1 2 3 4 5 6 7 8
Log base 2 of 1.000000 is 0.000000
Log base 2 of 2.000000 is 1.000000
Log base 2 of 3.000000 is 1.584963
Log base 2 of 4.000000 is 2.000000
Log base 2 of 5.000000 is 2.321928
Log base 2 of 6.000000 is 2.584963
Log base 2 of 7.000000 is 2.807355
Log base 2 of 8.000000 is 3.000000
on my system.

PS: I slightly modified your [Dark_Helmet's] code to eliminate an error message (no return value for "main") and to process all the arguments internally. Like this at the end:
Code:
  for (i=1; i < argc; ++i) {
    given_value = strtod( argv[i], NULL );

    log_base_2 = log2( given_value );
    printf( "Log base 2 of %f is %f\n",
          given_value,
          log_base_2 );
  }

  return 0;
PPS: As you see, FC4 defines a c99 script, which just calls gcc with the -std=c99 argument.

Last edited by PTrenholme; 09-29-2005 at 05:11 PM.
 
Old 09-29-2005, 07:24 PM   #18
PTrenholme
Senior Member
 
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 4,186

Rep: Reputation: 347Reputation: 347Reputation: 347Reputation: 347
I've reported the manual error to the glibc maintainers.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
INIT NOT FOUND + HDA(x) NOT FOUND fred99 Linux - Software 1 02-25-2005 02:10 PM
CDROM found/not found SUSE 9.2 dirdej SUSE / openSUSE 4 01-14-2005 11:58 PM
gcc vs. g++ -> iostream lib found vs. not found CooManChu Linux - General 1 12-11-2004 09:20 AM
weirdness with log2() spuzzzzzzz Programming 5 08-08-2004 05:45 PM
PDC 20276 - Promise Fasttrack 133 found but still not found.. FransE Linux - Hardware 3 02-16-2004 07:44 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:32 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration