blob: 779a6e00eeea6b6c09f9a8302927c15e372116e4 (
plain)
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
/*
* oregano-utils.c
*
*
* Author:
* Richard Hult <rhult@hem.passagen.se>
* Ricardo Markiewicz <rmarkie@fi.uba.ar>
* Andres de Barbara <adebarbara@fi.uba.ar>
* Marc Lorber <lorber.marc@wanadoo.fr>
*
* Web page: https://github.com/marc-lorber/oregano
*
* Copyright (C) 1999-2001 Richard Hult
* Copyright (C) 2003,2006 Ricardo Markiewicz
* Copyright (C) 2009-2012 Marc Lorber
*
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include <string.h>
#include <gtk/gtk.h>
#include "oregano-utils.h"
gdouble
oregano_strtod (const gchar *str, const gchar unit)
{
gdouble ret;
gchar *endptr, *c;
if (!str)
return 0.0;
ret = g_ascii_strtod (str, &endptr);
for (c = endptr; *c; c++) {
switch (*c) {
case 'T':
ret *= 1e12;
return ret;
case 'G':
ret *= 1e9;
return ret;
case 'M':
ret *= 1e6;
return ret;
case 'k':
ret *= 1e3;
return ret;
case 'm':
ret *= 1e-3;
return ret;
case 'u':
ret *= 1e-6;
return ret;
case 'n':
ret *= 1e-9;
return ret;
case 'p':
ret *= 1e-12;
return ret;
case 'f':
ret *= 1e-15;
return ret;
default:
if (*c == unit)
return ret;
break;
}
}
return ret;
}
|