I frequently find myself writing max value functions that search through an array of doubles I use functions like these to normalize data before graphic display.
Is there a better way to find the max value of an array of doubles? Is there a standard function to find the max value in an array? Are there some intrinsic for this operation? I remember specialized ASM instruction existed in DSP chips.
Yep! There’s a function called
std::max_element:You’ll need to
#include <algorithm>to do this. That header has a whole bunch of goodies in it, and it’s worth taking the time to learn more about the STL containers and algorithms libraries, as they can make your life so much easier.As long as we’re on the subject, consider looking into
std::vectororstd::arrayas replacements for raw C++ arrays. They’re safer and a bit easier to use.Hope this helps!