pflag
pflag copied to clipboard
First-pass adding complex flags.
This is a first stab at adding complex128 as a flag type. I have basically cloned the float64 code and substituted Complex
and complex128
and added a few complex numbers in one unit-test.
Unfortunately, the strconv.ParseComplex function only seems to exist from Go 1.15 onwards, so I have made the complex128 flag code conditional on the go1.15
tag.
@vatine Can you tell me what these are used for? Purely curious.
@cornfeedhobo I find various fractals cool, including (but not limited to) Newton-Raphson fractals. So, I thought, why not write a ... thing that computes fractals and spit them out to files (probably only PNGs to start with), using cobra to select the subcommand/fractal to compute.
But, if you specify the polynomial to feed into Newton-Raphson as an actual polynomial, you then have to find the roots. It is much easier to specify the roots, and then compute the polynomial by (z - r0) * (z - r1) * ... * (z -rn). So, I need a way of specifying complex numbers on the command line, and, well, one thing fed another.
It's also handy to specify the "lower left corner" and "the upper right corner" of the resulting image as complex numbers, and (again) flags would be handy.
@vatine Interesting! Well, this repo seems to get random levels of support from it's owners, so I've started a fork. If they don't get back to you soon and merge this, I'll probably create this type over on my fork. Instructions for using my fork with cobra are in the readme.
@vatine since it's been a while on your PR, I've pushed similar work to my fork. It looks like you've missed a few things, but I've cleaned everything up.