C Library Problem: M_E Constant Issues

  • Thread starter Peter P.
  • Start date
In summary, the conversation discusses the use of the constant M_E from the math.h library in an assignment. The speaker encountered an issue with the compiler recognizing the constant and asks if it is a problem with the compiler or the library. The other speaker mentions that the M_* constants are not part of the C standard and may require an explicit definition in modern compilers. This clarification resolves the issue for the first speaker.
  • #1
Peter P.
23
0
I was working on an assignment and i needed to use a constant that is defined in the math.h library (M_E). But when i tried to use it, the compiler took it as a normal variable that had not been initialized or anything. So my question is, is this just because of the compiler i was using, or is there something wrong with the library on my laptop?
 
Technology news on Phys.org
  • #2
According to this wiki article (http://en.wikipedia.org/wiki/Math.h), the M_* constants aren't standard. It also says,
While these constants are common, they are not part of the C standard, so most modern compilers require an explicit definition (such as _USE_MATH_DEFINES in Microsoft Visual C++ [1]) for them to be defined when including math.h.
 
  • #3
Thanks for the answer, that cleared it up for me.
 

What is the M_E constant in the C library?

The M_E constant in the C library is a predefined constant that represents the mathematical constant e, which is approximately equal to 2.71828.

Why is the M_E constant causing problems in the C library?

The M_E constant can cause problems in the C library if it is not properly defined or if its value is incorrect. This can lead to errors in mathematical calculations that use the M_E constant.

How can I fix M_E constant issues in the C library?

To fix M_E constant issues in the C library, you can check that the constant is properly defined and that its value is correct. If necessary, you can also re-define the constant with the correct value.

Are there any alternative constants to M_E in the C library?

Yes, there are alternative constants to M_E in the C library, such as the M_PI constant which represents the mathematical constant pi (π). These alternative constants may be more suitable for certain mathematical calculations.

Can I use the M_E constant in my own C programs?

Yes, you can use the M_E constant in your own C programs as long as it is properly defined and its value is correct. However, it is always a good practice to check for any potential issues with predefined constants before using them in your code.

Similar threads

  • Programming and Computer Science
Replies
2
Views
354
  • Programming and Computer Science
Replies
4
Views
3K
  • Programming and Computer Science
Replies
15
Views
5K
  • Programming and Computer Science
Replies
12
Views
2K
  • Programming and Computer Science
Replies
7
Views
440
  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
Replies
7
Views
2K
  • Programming and Computer Science
Replies
12
Views
3K
  • Programming and Computer Science
Replies
29
Views
5K
Back
Top