better error handling
This commit is contained in:
parent
d267c75b83
commit
a1f1ecd072
|
@ -129,9 +129,12 @@ float interpolate(float x1, float y1, float x2, float y2, float x) {
|
||||||
return interpolateMsg("", x1, y1, x2, y2, x);
|
return interpolateMsg("", x1, y1, x2, y2, x);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Another implementation, which one is faster?
|
||||||
|
*/
|
||||||
int findIndex2(const float array[], unsigned size, float value) {
|
int findIndex2(const float array[], unsigned size, float value) {
|
||||||
efiAssert(!cisnan(value), "NaN in findIndex", 0);
|
efiAssert(!cisnan(value), "NaN in findIndex2", 0);
|
||||||
efiAssert(size > 1, "NaN in findIndex", 0);
|
efiAssert(size > 1, "size in findIndex", 0);
|
||||||
// if (size <= 1)
|
// if (size <= 1)
|
||||||
// return size && *array <= value ? 0 : -1;
|
// return size && *array <= value ? 0 : -1;
|
||||||
|
|
||||||
|
@ -157,8 +160,11 @@ int findIndex2(const float array[], unsigned size, float value) {
|
||||||
* @returns the highest index within sorted array such that array[i] is greater than or equal to the parameter
|
* @returns the highest index within sorted array such that array[i] is greater than or equal to the parameter
|
||||||
* @note If the parameter is smaller than the first element of the array, -1 is returned.
|
* @note If the parameter is smaller than the first element of the array, -1 is returned.
|
||||||
*/
|
*/
|
||||||
int findIndex(const float array[], int size, float value) {
|
int findIndexMsg(const char *msg, const float array[], int size, float value) {
|
||||||
efiAssert(!cisnan(value), "NaN in findIndex", 0);
|
if (cisnan(value)) {
|
||||||
|
firmwareError(CUSTOM_ERR_6530, "NaN in findIndex%s", msg);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (value < array[0])
|
if (value < array[0])
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -197,6 +203,10 @@ int findIndex(const float array[], int size, float value) {
|
||||||
return middle;
|
return middle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int findIndex(const float array[], int size, float value) {
|
||||||
|
return findIndexMsg("", array, size, value);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief One-dimensional table lookup with linear interpolation
|
* @brief One-dimensional table lookup with linear interpolation
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#define INTERPOLATION_A(x1, y1, x2, y2) ((y1 - y2) / (x1 - x2))
|
#define INTERPOLATION_A(x1, y1, x2, y2) ((y1 - y2) / (x1 - x2))
|
||||||
|
|
||||||
int findIndex(const float array[], int size, float value);
|
int findIndex(const float array[], int size, float value);
|
||||||
|
int findIndexMsg(const char *msg, const float array[], int size, float value);
|
||||||
int findIndex2(const float array[], unsigned size, float value);
|
int findIndex2(const float array[], unsigned size, float value);
|
||||||
float interpolate(float x1, float y1, float x2, float y2, float x);
|
float interpolate(float x1, float y1, float x2, float y2, float x);
|
||||||
float interpolateMsg(const char *msg, float x1, float y1, float x2, float y2, float x);
|
float interpolateMsg(const char *msg, float x1, float y1, float x2, float y2, float x);
|
||||||
|
@ -42,12 +43,12 @@ float interpolate3d(float x, float xBin[], int xBinSize, float y, float yBin[],
|
||||||
return NAN;
|
return NAN;
|
||||||
}
|
}
|
||||||
|
|
||||||
int xIndex = findIndex(xBin, xBinSize, x);
|
int xIndex = findIndexMsg("x", xBin, xBinSize, x);
|
||||||
#if DEBUG_INTERPOLATION
|
#if DEBUG_INTERPOLATION
|
||||||
if (needInterpolationLogging())
|
if (needInterpolationLogging())
|
||||||
printf("X index=%d\r\n", xIndex);
|
printf("X index=%d\r\n", xIndex);
|
||||||
#endif
|
#endif
|
||||||
int yIndex = findIndex(yBin, yBinSize, y);
|
int yIndex = findIndexMsg("y", yBin, yBinSize, y);
|
||||||
if (xIndex < 0 && yIndex < 0) {
|
if (xIndex < 0 && yIndex < 0) {
|
||||||
#if DEBUG_INTERPOLATION
|
#if DEBUG_INTERPOLATION
|
||||||
if (needInterpolationLogging())
|
if (needInterpolationLogging())
|
||||||
|
|
Loading…
Reference in New Issue