geomagnetic-field: Fix comparison of float 16/282016/3 accepted/tizen_7.0_unified_hotfix tizen_7.0_hotfix accepted/tizen/7.0/unified/20221110.063826 accepted/tizen/7.0/unified/hotfix/20221116.104824 accepted/tizen/unified/20220930.020554 tizen_7.0_m2_release
authorTaeminYeom <taemin.yeom@samsung.com>
Mon, 26 Sep 2022 08:11:56 +0000 (17:11 +0900)
committerTaeminYeom <taemin.yeom@samsung.com>
Thu, 29 Sep 2022 00:48:04 +0000 (09:48 +0900)
Change-Id: Idb818706c7fc5572948ca39e5a7b04cef10eb868
Signed-off-by: TaeminYeom <taemin.yeom@samsung.com>
src/api/geomagnetic-field.c

index 771fbb5..8093ccb 100644 (file)
@@ -53,6 +53,12 @@ float g_inclination = 0;
 
 static void E0000(int IENTRY, int maxdeg, float alt, float glat, float glon, float time, float *dec, float *dip, float *ti, float *gv);
 
+static int is_float_equal(float f1, float f2)
+{
+       float precision = 0.00001f;
+       return ((f1 - precision) < f2) && ((f1 + precision) > f2);
+}
+
 int getDeclination(float *decl)
 {
        if (decl == NULL)
@@ -172,7 +178,7 @@ GEOMG1:
        sp[1] = srlon;
        cp[1] = crlon;
 
-       if (alt != oalt || glat != olat) {
+       if (!is_float_equal(alt, oalt) || !is_float_equal(glat, olat)) {
                q = sqrt(a2-c2*srlat2);
                q1 = alt*q;
                q2 = ((q1+a2)/(q1+b2))*((q1+a2)/(q1+b2));
@@ -184,7 +190,7 @@ GEOMG1:
                ca = (alt+d)/r;
                sa = c2*crlat*srlat/(r*d);
        }
-       if (glon != olon) {
+       if (!is_float_equal(glon, olon)) {
                for (m = 2; m <= maxord; m++) {
                        sp[m] = sp[1]*cp[m-1]+cp[1]*sp[m-1];
                        cp[m] = cp[1]*cp[m-1]-sp[1]*sp[m-1];
@@ -196,7 +202,7 @@ GEOMG1:
        for (n = 1; n <= maxord; n++) {
                ar = ar*aor;
                for (m = 0, D3 = 1, D4 = (n+m+D3)/D3; D4 > 0; D4--, m += D3) {
-                       if (alt != oalt || glat != olat) {
+                       if (!is_float_equal(alt, oalt) || !is_float_equal(glat, olat)) {
                                if (n == m && m != 0) {
                                        *(p+n+m*13) = st**(p+n-1+(m-1)*13);
                                        dp[m][n] = st*dp[m-1][n-1]+ct**(p+n-1+(m-1)*13);
@@ -215,7 +221,7 @@ GEOMG1:
                                }
                        }
 S50:
-                       if (time != otime) {
+                       if (!is_float_equal(time, otime)) {
                                tc[m][n] = c[m][n]+dt*cd[m][n];
                                if (m != 0) tc[n][m-1] = c[n][m-1]+dt*cd[n][m-1];
                        }
@@ -232,7 +238,7 @@ S50:
                        bp += (fm[m]*temp2*par);
                        br += (fn[n]*temp1*par);
 
-                       if (st == 0.0 && m == 1) {
+                       if (is_float_equal(st, 0.0) && m == 1) {
                                if (n == 1) pp[n] = pp[n-1];
                                else pp[n] = ct*pp[n-1]-k[m][n]*pp[n-2];
                                parp = ar*pp[n];
@@ -240,7 +246,7 @@ S50:
                        }
                }
        }
-       if (st == 0.0) bp = bpp;
+       if (is_float_equal(st, 0.0)) bp = bpp;
        else bp /= st;
 
        bx = -bt*ca-br*sa;