1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
/* START LIBRARY DESCRIPTION *********************************************
FLOAT.LIB
Copyright (c) 2006, Avtech Electrosystems Ltd.
DESCRIPTION:
Functions that deal with strings and floating point numbers.
SUPPORT LIB'S:
END DESCRIPTION **********************************************************/
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <glib/gprintf.h>
#include "globals.h"
#include "string_utils.h"
void Float_To_Text(int decimal_digits,float number_in, gchar ** text_out)
{
g_assert (*text_out == NULL);
if (fabs(number_in)<1.1*smallest_allowed_number) {
if (number_in<0.0) {
*text_out = g_strdup_printf("-0.%0*d",decimal_digits,0);
} else {
*text_out = g_strdup_printf("0.%0*d",decimal_digits,0);
}
return;
}
*text_out = g_strdup_printf("%.*e", decimal_digits, number_in);
}
/*----------------------------------------------------------------------------------------------------------*/
gboolean String_is_it_numeric(char *parameter)
{
GRegex *numeric_regex = g_regex_new ( "\\s*[+-]?(\\d*\\.\\d+|\\d+(\\.\\d*)?)\\s*(e\\s*[+-]?\\d+)?\\s*",
G_REGEX_CASELESS,
0,
NULL);
gboolean match = g_regex_match (numeric_regex, parameter, 0, NULL);
g_regex_unref (numeric_regex);
return match;
}
|