Skip to content

Commit 5d1d33d

Browse files
committed
Calculate on the go
1 parent 5d39109 commit 5d1d33d

File tree

4 files changed

+17
-20
lines changed

4 files changed

+17
-20
lines changed

include/geodesic.h

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ struct Vector {
2828
};
2929

3030
long double sqr(long double operand);
31+
long double double_fac(int x);
3132
long double atan2_modified(long double y, long double x);
3233
long double normalise_a(long double x);
3334
long double normalise_c(long double x);

src/math.c

+13
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,19 @@ long double sqr(long double operand)
66
return operand * operand;
77
}
88

9+
long double double_fac(int x)
10+
{
11+
if (x == -3)
12+
return -1;
13+
else {
14+
long double y = 1;
15+
while (x > 0) {
16+
y *= x;
17+
x -= 2;
18+
}
19+
return y;
20+
}
21+
}
922

1023
long double atan2_modified(long double y, long double x)
1124
{

src/mpblock.c

+1-14
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,8 @@
11
#include <math.h>
2+
#include "math.h"
23
#include "io.h"
34
#include "mpblock.h"
45

5-
long double double_fac(int x)
6-
{
7-
if (x == -3)
8-
return -1;
9-
else {
10-
long double y = 1;
11-
while (x > 0) {
12-
y *= x;
13-
x -= 2;
14-
}
15-
return y;
16-
}
17-
}
18-
196
int isblock(struct Coordinates *vertex)
207
{
218
int block = 1;

src/vincenty.c

+2-6
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
#include "geodesic.h"
33
#include "vincenty.h"
44

5-
const long double Alookup[5] = {25.0l/16384.0l, 1.0l/256.0l, 1.0l/64.0l, 1.0l/4.0l, 1.0l};
6-
75
const long double Blookup[8][4] = {
86
{-1.0l/2.0l,3.0l/16.0l,-1.0l/32.0l,19.0l/2048.0l},
97
{-1.0l/16.0l,1.0l/32.0l,-9.0l/2048.0l,7.0l/4096.0l},
@@ -64,10 +62,8 @@ long double helmertA(long double calp)
6462
usq = calp * ECC2;
6563
k1 = sqrtl(1.0l + usq);
6664
k1 = (k1 - 1.0l) / (k1 + 1.0l);
67-
for (k = 0; k < 5; k++) {
68-
A *= sqr(k1);
69-
A += Alookup[k];
70-
}
65+
for (k = 0; k < 11; k++)
66+
A += sqr(double_fac(2 * k - 3) / double_fac(2 * k) * powl(k1, k));
7167
A /= (1 - k1);
7268
return A;
7369
}

0 commit comments

Comments
 (0)