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.
The value of this constant is positive 1.7976931348623157E+308.
Use a hash to pick unique n maximum elements of both arrays, giving priority to A[]. Initialize result array as empty. Traverse through A[], copy those elements of A[] that are present in the hash. This is done to keep the order of elements the same.
You can declare an array of any data type (i.e. int, float, double, char) in C.
Yep! There's a function called std::max_element
:
double arr[LENGTH] = /* ... */
double max = *std::max_element(arr, arr + LENGTH);
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::vector
or std::array
as replacements for raw C++ arrays. They're safer and a bit easier to use.
Hope this helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With