d02111da4f
- Code refactoring - Optimization of code (for example, log2(n) searching) and memory usage - Some possible memory corruption fixed - Previous graph will be erased from window if error occured - Fixed bug with provided array of non-sorted points: so now you can pass points in any order - Fixed important bug with graphic rendering (big thanks to turbocat for asm rounding function) - Changed error messages; now you can see line/byte of file where syntax error is; added checking if provided frame of graph is invalid - Autochoosing of an optimal single step for both axises - Added support for reading any number of different functions. You will have to end previous function with ';' if you want to pass another one. They will be rendered on a graph in order you passed them. git-svn-id: svn://kolibrios.org@9778 a494cfbc-eb01-0410-851d-a64ba20cac60
68 lines
1.2 KiB
C
Executable File
68 lines
1.2 KiB
C
Executable File
#include "func.h"
|
|
#include <math.h> // For fabs()
|
|
|
|
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');
|
|
}
|
|
|
|
// ýòà ôóíêöèÿ - âåëîñèïåä. íî ïðîùå áûëî íàïèñàòü ÷åì íàéòè.
|
|
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;
|
|
}
|
|
|
|
int isequal(double a, double b) {
|
|
return fabs(a-b) < EQUALITY_VAL;
|
|
} |