New answers tagged

5

This is not a rounding error, but a wrong application of financial formulas. The formula used for your loan payment is based on financial math designed for a periodic payment with an interest rate for the same period, assuming compound interests. In your usage of this formula, you base yourself on an annual rate r. You calculate the periodic rate ...


2

Since it is a template you can have complex<int> - what should the return-type be for the "usual norm"? float? double? (Using int would be natural for a template, but doesn't work well.) Obviously it can be solved in various ways, but here the standard avoid that question by returning what would normally be the square of the norm.


6

Aside from the already given reasons, there is a strong performance reason: taking the square root is significantly slower than the other needed calculations. For many applications, the returned value is perfectly sufficient (like comparison to other norm values), and taking the square root would be wasted effort. If you happen to need the square root, you ...


25

Christophe's post, whilst fully correct, does not actually answer the question why the terms look like they do. To give you definite answer for the reasons, you would have to ask someone from the C++ standard committee, but let me make an "educated guess": There was already a function name std::abs in use for the euclidean norm for float and double values,...


38

This is not a C++ library issue but a question of mathematical terminology. In mathematics, a norm can mean different things: What you call norm is the Euclidian norm, which is the distance to the origin. In C++ it's abs(). This naming convention has the advantage of being consistent for complex and for real numbers (the origin in the latter case being ...


8

You can encode the 8! possible permutations of the corners in 16 bits, and the 12! possible permutations in 29 bits, by numbering the permutations from 1 to 8! (or 1 to 12!), and storing the number. I found a description for how to make this encoding efficient here, using a Lehmer code. In an analogous manner, you can pack the 3^8=6561 orientations of the ...


Top 50 recent answers are included