473,323 Members | 1,574 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

syntax for e (natural logs)

I was wondering what, if there is even one, the syntax for the constant e
is. I figured it would be in math.h right alongside 'pi' but it doesn't
seem to be there, does it in fact exist? i did many searches online but it
is hard to search for the letter 'e', even tried natural logs but came up
dry. Any help would be appreciated, thank you!

~Senturon
Nov 14 '05 #1
10 17304
Senturon writes:
I was wondering what, if there is even one, the syntax for the constant e
is. I figured it would be in math.h right alongside 'pi' but it doesn't
seem to be there, does it in fact exist? i did many searches online but it
is hard to search for the letter 'e', even tried natural logs but came up
dry. Any help would be appreciated, thank you!


exp(1.0)
should work. It's in <math.h>.

Nov 14 '05 #2
Senturon wrote:
I was wondering what, if there is even one, the syntax for the constant e
is. I figured it would be in math.h right alongside 'pi' but it doesn't
seem to be there, does it in fact exist? i did many searches online but it
is hard to search for the letter 'e', even tried natural logs but came up
dry. Any help would be appreciated, thank you!


In fact neither definitions of pi nor e are required by the C90
standard. The only macro math.h always defines is HUGE_VAL. However,
math.h does supply some functions which you can use to obtain these
constants at runtime.

For pi: acos(-1.0)
For e: exp(1.0)

Alternatively, if you'd rather have them at compile-time, just stick the
constants in yourself:

#define PI (3.1415926535897932384626433832795028841971693994L )
#define E (2.7182818284590452353602874713526624977572470937L )

--
Derrick Coetzee
I grant this newsgroup posting into the public domain. I disclaim all
express or implied warranty and all liability. I am not a professional.
Nov 14 '05 #3
Senturon wrote:
I was wondering what, if there is even one, the syntax for the constant e
is. I figured it would be in math.h right alongside 'pi'
Pi isn't in <math.h> if your compiler is in standard-conforming mode. but it doesn't
seem to be there, does it in fact exist? i did many searches online but it
is hard to search for the letter 'e', even tried natural logs but came up
dry. Any help would be appreciated, thank you!


Put into your code:

const double pi=3.14159265358979324;
const double e= 2.71828182845904524;

you could, of course, perversely use
#define PI (4*atan(1))
or
#define PI (6*atan(1/sqrt(3)))

along with
#define E (exp(1))
Nov 14 '05 #4
Martin Ambuhl <ma*****@earthlink.net> writes:
Senturon wrote:
I was wondering what, if there is even one, the syntax for the constant e
is. I figured it would be in math.h right alongside 'pi'
Pi isn't in <math.h> if your compiler is in standard-conforming mode.
but it doesn't
seem to be there, does it in fact exist? i did many searches online but it
is hard to search for the letter 'e', even tried natural logs but came up
dry. Any help would be appreciated, thank you!


Put into your code:

const double pi=3.14159265358979324;
const double e= 2.71828182845904524;


Which is ok unless you need precise values in type long double and/or
in a type with a mantissa of more than about 58 bits.
you could, of course, perversely use
#define PI (4*atan(1))
or
#define PI (6*atan(1/sqrt(3)))

along with
#define E (exp(1))


That actually makes sense if you assign it to a constant rather than
using a macro that potentially causes the values to be recomputed each
time you use it.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 14 '05 #5
snip
Alternatively, if you'd rather have them at compile-time, just stick the
constants in yourself:

#define PI (3.1415926535897932384626433832795028841971693994L )
#define E (2.7182818284590452353602874713526624977572470937L )


Why the terminal L? MPJ
Nov 14 '05 #6
"Senturon" <senturontemp-at-charter-dot-net> wrote in message
news:10*************@corp.supernews.com...
I was wondering what, if there is even one, the syntax for the constant e
is. I figured it would be in math.h right alongside 'pi' but it doesn't
seem to be there, does it in fact exist? i did many searches online but it
is hard to search for the letter 'e', even tried natural logs but came up
dry. Any help would be appreciated, thank you!

~Senturon


AFAIK, there is no C standard for common math constants but most Unix
implementations have them in <math.h>, all with a prefix of "M_". Microsoft
did not include these constants until VC7 and then only if you define the
symbol _USE_MATH_DEFINES as demonstrated below.

The constant for e is: M_E

Dag
From VC7 math.h:

#ifdef _USE_MATH_DEFINES

/* Define _USE_MATH_DEFINES before including math.h to expose these macro
* definitions for common math constants. These are placed under an #ifdef
* since these commonly-defined names are not part of the C/C++ standards.
*/

/* Definitions of useful mathematical constants
* M_E - e
* M_LOG2E - log2(e)
* M_LOG10E - log10(e)
* M_LN2 - ln(2)
* M_LN10 - ln(10)
* M_PI - pi
* M_PI_2 - pi/2
* M_PI_4 - pi/4
* M_1_PI - 1/pi
* M_2_PI - 2/pi
* M_2_SQRTPI - 2/sqrt(pi)
* M_SQRT2 - sqrt(2)
* M_SQRT1_2 - 1/sqrt(2)
*/

#define M_E 2.71828182845904523536
#define M_LOG2E 1.44269504088896340736
#define M_LOG10E 0.434294481903251827651
#define M_LN2 0.693147180559945309417
#define M_LN10 2.30258509299404568402
#define M_PI 3.14159265358979323846
#define M_PI_2 1.57079632679489661923
#define M_PI_4 0.785398163397448309616
#define M_1_PI 0.318309886183790671538
#define M_2_PI 0.636619772367581343076
#define M_2_SQRTPI 1.12837916709551257390
#define M_SQRT2 1.41421356237309504880
#define M_SQRT1_2 0.707106781186547524401

#endif /* _USE_MATH_DEFINES */
Nov 14 '05 #7
>>#define PI (3.1415926535897932384626433832795028841971693994L )
#define E (2.7182818284590452353602874713526624977572470937L )


Why the terminal L? MPJ


To make them long double constants; without F or L, floating
point constants are assumed to be double constants, so you
would lose all the excess digits of precision between double
and long double without the L.

Nov 14 '05 #8
Senturon <senturontemp-at-charter-dot-net> wrote:

I was wondering what, if there is even one, the syntax for the constant e
is.


Some implementations define the macro M_E when not in strict ANSI C
mode. For true portability, you can use exp(1.0).

-Larry Jones

I kind of resent the manufacturer's implicit assumption
that this would amuse me. -- Calvin
Nov 14 '05 #9

"Dag Viken" <da*******@earthlink.net> wrote in message
news:EQ****************@newsread2.news.atl.earthli nk.net...
AFAIK, there is no C standard for common math constants but most Unix
implementations have them in <math.h>, all with a prefix of "M_".


Make that "most Posix implementations." It's been mentioned several times
that the C standard doesn't permit these constants to appear by a default
invocation of <math.h>. As you pointed out, the compilers vary in the
scheme employed to make them appear, and in whether they are defined so as
to make them work in long double as well as double. As Microsoft doesn't
support long double as distinct from double, their omission in that
department may not be surprising.
Nov 14 '05 #10
"Tim Prince" <tp*****@nospamcomputer.org> writes:
"Dag Viken" <da*******@earthlink.net> wrote in message
news:EQ****************@newsread2.news.atl.earthli nk.net...
AFAIK, there is no C standard for common math constants but most Unix
implementations have them in <math.h>, all with a prefix of "M_".


Make that "most Posix implementations." It's been mentioned several times
that the C standard doesn't permit these constants to appear by a default
invocation of <math.h>. As you pointed out, the compilers vary in the
scheme employed to make them appear, and in whether they are defined so as
to make them work in long double as well as double. As Microsoft doesn't
support long double as distinct from double, their omission in that
department may not be surprising.


If Microsoft doesn't support type "long double" at all, their compiler
is not conforming. If they support "long double" with the same
representation as "double", that's perfectly legitimate, as long as
both types satisfy the minimum requirements.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 14 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

699
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro...
303
by: mike420 | last post by:
In the context of LATEX, some Pythonista asked what the big successes of Lisp were. I think there were at least three *big* successes. a. orbitz.com web site uses Lisp for algorithms, etc. b....
35
by: Moosebumps | last post by:
Does anyone here find the list comprehension syntax awkward? I like it because it is an expression rather than a series of statements, but it is a little harder to maintain it seems. e.g. you...
28
by: Paul McGuire | last post by:
Well, after 3 days of open polling, the number of additional votes have dropped off pretty dramatically. Here are the results so far: Total voters: 55 (with 3 votes each) Votes for each choice...
8
by: Ike | last post by:
I am hoping someone can help me with the proper syntax for this. I have an attribute, called, say "name," such that: <set name="something">thename</set> However, the value for name, is...
177
by: C# Learner | last post by:
Why is C syntax so uneasy on the eye? In its day, was it _really_ designed by snobby programmers to scare away potential "n00bs"? If so, and after 50+ years of programming research, why are...
21
by: Dmitry Anikin | last post by:
I mean, it's very convenient when default parameters can be in any position, like def a_func(x = 2, y = 1, z): ... (that defaults must go last is really a C++ quirk which is needed for overload...
11
by: Frankie | last post by:
I have been learning about the AsyncOperation class and came across this code (sorry I got it a few days ago and don't remember the specific link). Anyway, I am wondering what the tilde (~) on...
13
by: Neal Becker | last post by:
In hindsight, I am disappointed with the choice of conditional syntax. I know it's too late to change. The problem is y = some thing or other if x else something_else When scanning this my...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.