Code:
// C++ program to demonstrate
// example of norm() function.
#include <bits/stdc++.h>
using namespace std;
// driver function
int main ()
{
// initializing the complex: (4.0+3.0i)
complex<double> complexnumber (4.0, 3.0);
// use of norm()function
cout << "The norm of " << complexnumber << " is ";
cout << norm(complexnumber) << endl;
return 0;
}
Output:
The norm of (4,3) is 25
I realized this is why I couldn’t do complex-plane version of Popcorn Fractal that I long dream about.
EDIT: I found that the answer seem to be just doing a sqr(norm(vec2)) to get the same result.
Yes, I don’t know why, but the std::norm() in C++ computes the squared magnitude rather than the vector norm.
The norm() function in G’MIC just computes the Euclidean norm of a vector, which is obviously \sqrt{x^2+y^2} for a vector (x,y).
G’MIC follows norm as a mathematician would read it: the Euclidean metric — the L2 norm.
My understanding is that C++ offers its norm() as a “cheap distance metric.” If I sort a bunch of points by distance from a reference (origin), I would get the same sort order whether or not I took the square root – and taking a square root is a relatively expensive computation. So if I can avoid it and – for certain applications – get the same result, I’d drop computing the square root. Especially if all I have is @afre 's old laptop
Also, I forgot to mention. norm() isn’t found on the G’MIC reference. And there should be a note that to use a*a+b*b to get the same result as in c++.
It’s there — easy to miss because it is not spelled out as such. In the math parser, it is documented as normP for P in {2, 3, 4…}. Omit the P( norm() ) then it defaults to 2, as documented in Mathematical Expressions - Vector Calculus. See tenth bullet point. Then, for the command line parser, you can take an image’s point-wise L2 norm, tutorial at norm.
Ah me. That was probably fallout of the new quantum-entanglement commands being incorporated into G’MIC. I’m finding the time-and-space inversion tutorials a bit tricky. If images of the Brooklyn Army Terminal Building in Bay Ridge show up on your laptop, don’t be (too) alarmed. They’re harmless. Mostly. I think. @David_Tschumperle , of course, has no idea what these are, since he hasn’t even conceived of them yet, so he should find the documentation interesting. That’s the beauty of temporal entanglements: I can experiment and document these commands even before they’re written, so – for once! – I am ahead of the documentation game. Always interesting to see what G’MIC 3.5 will bring to us in 2025, even if there aren’t any Feynman diagrams linking causality. I know what I am doing. I mean, I’m pretty sure of that…