Add MSVC-specific text by Hans Breuer.
[platform/upstream/glib.git] / tests / strtod-test.c
1 #include <glib.h>
2 #include <locale.h>
3 #include <string.h>
4 #include <math.h>
5
6 void
7 test_string (char *number, double res)
8 {
9   gdouble d;
10   char *locales[] = {"sv_SE", "en_US", "fa_IR", "C"};
11   int l;
12   char *end;
13
14   for (l = 0; l < G_N_ELEMENTS (locales); l++)
15     {
16       setlocale (LC_NUMERIC, locales[l]);
17       d = g_ascii_strtod (number, &end);
18       if (d != res)
19         g_print ("g_ascii_strtod for locale %s failed\n", locales[l]);
20       if (*end != 0)
21         g_print ("g_ascii_strtod for locale %s endptr was wrong\n", locales[l]);
22     }
23 }
24
25
26 int 
27 main ()
28 {
29   gdouble d;
30   char buffer[G_ASCII_DTOSTR_BUF_SIZE];
31
32   test_string ("123.123", 123.123);
33   test_string ("123.123e2", 123.123e2);
34   test_string ("123.123e-2", 123.123e-2);
35   test_string ("-123.123", -123.123);
36   test_string ("-123.123e2", -123.123e2);
37   test_string ("-123.123e-2", -123.123e-2);
38   
39   d = 179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.0;
40   g_assert (d == g_ascii_strtod (g_ascii_dtostr (buffer, sizeof (buffer), d), NULL));
41
42   d = -179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.0;
43   g_assert (d == g_ascii_strtod (g_ascii_dtostr (buffer, sizeof (buffer), d), NULL));
44   
45   d = pow (2.0, -1024.1);
46   g_assert (d == g_ascii_strtod (g_ascii_dtostr (buffer, sizeof (buffer), d), NULL));
47   
48   d = -pow (2.0, -1024.1);
49   g_assert (d == g_ascii_strtod (g_ascii_dtostr (buffer, sizeof (buffer), d), NULL));
50   
51
52   return 0;
53 }