2022-04-12 02:42:06 +02:00
|
|
|
|
#include "func.h"
|
2022-04-21 23:26:05 +02:00
|
|
|
|
#include <math.h> // For fabs()
|
2022-04-12 02:42:06 +02:00
|
|
|
|
|
|
|
|
|
char debuf[50] = "";
|
|
|
|
|
|
|
|
|
|
double textwidth(const char* s, int len) {
|
|
|
|
|
int i;
|
|
|
|
|
for (i = 0; i < len; i++)
|
|
|
|
|
if (s[i] == 0)
|
|
|
|
|
break;
|
|
|
|
|
return i * 6;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
double textheight(const char* s, int len) {
|
|
|
|
|
return 8.0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int isalpha(char c) {
|
|
|
|
|
return (c==' ' || c=='\n' || c=='\t' || c=='\r');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>. <20><> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>.
|
|
|
|
|
double convert(const char* s, int* len) {
|
|
|
|
|
int i;
|
|
|
|
|
double sign, res, tail, div;
|
|
|
|
|
res = 0.0;
|
|
|
|
|
i = 0;
|
|
|
|
|
while (s[i] && isalpha(s[i])) i++;
|
|
|
|
|
if (len) *len=i;
|
|
|
|
|
if (s[i] == '\0')
|
|
|
|
|
return ERROR_END;
|
|
|
|
|
|
|
|
|
|
sign=1.0;
|
|
|
|
|
if (s[i] == '-') {
|
|
|
|
|
sign=-1.0;
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
while (s[i] && s[i] >= '0' && s[i] <= '9') {
|
|
|
|
|
res *= 10.0;
|
|
|
|
|
res += s[i] - '0';
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
if (len) *len=i;
|
|
|
|
|
if (!s[i] || isalpha(s[i]))
|
|
|
|
|
return sign*res;
|
|
|
|
|
if (s[i] != '.' && s[i] != ',')
|
|
|
|
|
return ERROR;
|
|
|
|
|
i++;
|
|
|
|
|
if (len) *len=i;
|
|
|
|
|
if (!s[i])
|
|
|
|
|
return sign*res;
|
|
|
|
|
|
|
|
|
|
div = 1.0;
|
|
|
|
|
tail = 0.0;
|
|
|
|
|
while (s[i] && s[i] >= '0' && s[i] <= '9') {
|
|
|
|
|
tail *= 10.0;
|
|
|
|
|
tail += s[i] - '0';
|
|
|
|
|
div *= 10.0;
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
res += tail/div;
|
|
|
|
|
if (len) *len=i;
|
|
|
|
|
return sign*res;
|
2022-04-21 23:26:05 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int isequal(double a, double b) {
|
|
|
|
|
return fabs(a-b) < EQUALITY_VAL;
|
2022-04-12 02:42:06 +02:00
|
|
|
|
}
|