seeplus wrote: |
---|
(M_PI example) compiles fine with VS. |
#include <corecrt_math_defines.h>
instead of <cmath>/<math.h> and there's no need to have the #define. M_PI is "there" now.const double pi { 355.0/113.0 };
.
|
|
Mr Z wrote: |
---|
Is the stack on cpu cache and heap on RAM, or are they both on RAM? |
Mr Z wrote: |
---|
Why would the stack be limited in memory space? |
Mr Z wrote: |
---|
What method do you guys use to set the precision and compare float/double..what is the best/safest way to make comparisons? |
Mr Z wrote: |
---|
Flush has not been mentioned in my book... |
std::ios::sync_with_stdio(false);
My book did very simple & small float/double comparisons and they worked out nicely. Outside of my book then I come to find out that relational operations can be a problem because of precision. What method do you guys use to set the precision and compare float/double..what is the best/safest way to make comparisons? |
mbozzi wrote: |
---|
[Double] precision floating point numbers in [2^52, 2^53) can only represent integers. And numbers in [2^53, 2^54) can only represent even integers. It doesn't make any sense to test whether values of those magnitudes are within a tenth of each other, for instance [...] the epsilon needs to be a relative value expressed in terms of units in the last place |
it had one of a fixed number of memory models |
there is just sooo much & it never seems to end. |
|
|
With the machine epsilon & similar algorithms, do you guys just memorize the formula or do you treat it as reference. Or do you just know how it works & just have it in a template ready to use whenever needed, but do not memorize? |
Even for the professional programmer, it is impossible to first learn a whole programming language and then try to use it. A programming language is learned in part by trying out its facilities for small examples. Consequently, we always learn a language by mastering a series of subsets. The real question is not ‘‘Should I learn a subset first?’’ but ‘‘Which subset should I learn first?’’ For programming novices, learning the programming language should support the learning of effective programming techniques. ... The emphasis for both novices and experienced programmers should be concepts and techniques. The syntactic and semantic details of C++ are secondary to an understanding of design and programming techniques that C++ supports. ... Focussing on language-technical details can be fun, but it is not effective education. - Stroustrup (May 1999) https://www.stroustrup.com/new_learning.pdf |
|
|
"What you see here is the method IntroduceSelf() using private member Talk() to print a statement on the screen. In reality, the compiler embeds the this pointer in calling Talk, that is invoked as Talk(this, "Bla bla")." |
|
|
It does not matter where your data lives |
jonnin wrote: |
---|
It does not matter where your data lives |
The two most fundamental resources in a computer are time (to execute instructions) and space (memory to hold data and code). In C++, there are three ways to allocate memory to hold data: • Static memory: allocated by the linker and persisting as long as the program runs • Stack (automatic) memory: allocated when we call a function and freed when we return from the function • Dynamic (heap) memory: allocated by new and freed for possible reuse by delete Static memory poses no special problem: all is taken care of before the program starts to run Stack memory can be a problem because it is possible to use too much of it, but this is not hard to take care of. Dynamic memory allocation: Allocation is not predictable; that is, it is not guaranteed to be a constant time operation. Usually, it is not: in many implementations of new, the time needed to allocate a new object can increase dramatically after many objects have been allocated and deallocated. The free store may fragment; that is, after allocating and deallocating objects the remaining unused memory may be “fragmented” into a lot of little “holes” of unused space that are useless because each hole is too small to hold an object of the kind used by the application. - extracted from Stroustrup's PP&P |