From: Jürg Billeter Date: Wed, 21 Mar 2007 14:32:16 +0000 (+0000) Subject: improve support for numeric types, patch by Mathias Hasselmann test X-Git-Tag: VALA_0_0_8~12 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6589c1ace26ddc711e6e641e1a6a2a22af2d1804;p=platform%2Fupstream%2Fvala.git improve support for numeric types, patch by Mathias Hasselmann test 2007-03-21 Jürg Billeter * vapi/glib-2.0.vala: improve support for numeric types, patch by Mathias Hasselmann * tests/test-030.vala, tests/test-030.out, tests/test-031.vala, tests/test-031.out: test numeric types * tests/testrunner.sh: use c99 and math library * tests/Makefile.am: update svn path=/trunk/; revision=251 --- diff --git a/vala/ChangeLog b/vala/ChangeLog index 3bb9dea..f4f2310 100644 --- a/vala/ChangeLog +++ b/vala/ChangeLog @@ -1,5 +1,14 @@ 2007-03-21 Jürg Billeter + * vapi/glib-2.0.vala: improve support for numeric types, patch by + Mathias Hasselmann + * tests/test-030.vala, tests/test-030.out, tests/test-031.vala, + tests/test-031.out: test numeric types + * tests/testrunner.sh: use c99 and math library + * tests/Makefile.am: update + +2007-03-21 Jürg Billeter + * vala/valainterface.vala: implement marshalling support * vala/valacodegenerator.vala: support signals with interface parameters diff --git a/vala/tests/Makefile.am b/vala/tests/Makefile.am index be001c2..549eaf0 100644 --- a/vala/tests/Makefile.am +++ b/vala/tests/Makefile.am @@ -32,6 +32,8 @@ TESTS = \ test-027.vala \ test-028.vala \ test-029.vala \ + test-030.vala \ + test-031.vala \ $(NULL) EXTRA_DIST = \ @@ -94,4 +96,6 @@ EXTRA_DIST = \ test-027.out \ test-028.out \ test-029.out \ + test-030.out \ + test-031.out \ $(NULL) diff --git a/vala/tests/test-030.out b/vala/tests/test-030.out new file mode 100644 index 0000000..7a16172 --- /dev/null +++ b/vala/tests/test-030.out @@ -0,0 +1,8 @@ +int8: -128...127 +int16: -32768...32767 +int32: -2147483648...2147483647 +int64: -9223372036854775808...9223372036854775807 +uint8: 0...255 +uint16: 0...65535 +uint32: 0...4294967295 +uint64: 0...18446744073709551615 diff --git a/vala/tests/test-030.vala b/vala/tests/test-030.vala new file mode 100644 index 0000000..e28b4e0 --- /dev/null +++ b/vala/tests/test-030.vala @@ -0,0 +1,39 @@ +using GLib; + +class Maman.Foo { + static void main (string[] args) { + stdout.printf ( + "int8: %s...%s\n", + int8.MIN.to_string (), + int8.MAX.to_string ()); + stdout.printf ( + "int16: %s...%s\n", + int16.MIN.to_string (), + int16.MAX.to_string ()); + stdout.printf ( + "int32: %s...%s\n", + int32.MIN.to_string (), + int32.MAX.to_string ()); + stdout.printf ( + "int64: %s...%s\n", + int64.MIN.to_string (), + int64.MAX.to_string ()); + + stdout.printf ( + "uint8: %s...%s\n", + uint8.MIN.to_string (), + uint8.MAX.to_string ()); + stdout.printf ( + "uint16: %s...%s\n", + uint16.MIN.to_string (), + uint16.MAX.to_string ()); + stdout.printf ( + "uint32: %s...%s\n", + uint32.MIN.to_string (), + uint32.MAX.to_string ()); + stdout.printf ( + "uint64: %s...%s\n", + uint64.MIN.to_string (), + uint64.MAX.to_string ()); + } +} diff --git a/vala/tests/test-031.out b/vala/tests/test-031.out new file mode 100644 index 0000000..9fef60e --- /dev/null +++ b/vala/tests/test-031.out @@ -0,0 +1,18 @@ +float: range=1.17549e-38...3.40282e+38 + digits=24(6), exp=-125..128(-37..38) + epsilon=1.19209e-07, infinity=inf/-inf, nan=nan +float(1.19209e-07): nan=false, finite=true, normal=true, infinity=none +float(0): nan=false, finite=true, normal=false, infinity=none +float(1): nan=false, finite=true, normal=true, infinity=none +float(-inf): nan=false, finite=false, normal=false, infinity=negative +float(inf): nan=false, finite=false, normal=false, infinity=positive +float(nan): nan=true, finite=false, normal=false, infinity=none +double: range=2.22507e-308...1.79769e+308 + digits=53(15), exp=-1021..1024(-307..308) + epsilon=2.22045e-16, infinity=inf/-inf, nan=nan +double(2.22045e-16): nan=false, finite=true, normal=true, infinity=none +double(0): nan=false, finite=true, normal=false, infinity=none +double(1): nan=false, finite=true, normal=true, infinity=none +double(-inf): nan=false, finite=false, normal=false, infinity=negative +double(inf): nan=false, finite=false, normal=false, infinity=positive +double(nan): nan=true, finite=false, normal=false, infinity=none diff --git a/vala/tests/test-031.vala b/vala/tests/test-031.vala new file mode 100644 index 0000000..5ef4a01 --- /dev/null +++ b/vala/tests/test-031.vala @@ -0,0 +1,91 @@ +using GLib; + +class Maman.Foo { + const float[] FLOAT_TESTS = { + float.EPSILON, 0.0, 1.0, + -float.INFINITY, + float.INFINITY, + float.NAN + }; + + const double[] DOUBLE_TESTS = { + double.EPSILON, 0.0, 1.0, + -double.INFINITY, + double.INFINITY, + double.NAN + }; + + static void main (string[] args) { + stdout.printf ( + "float: range=%s...%s\n" + + " digits=%s(%s), exp=%s..%s(%s..%s)\n" + + " epsilon=%s, infinity=%s/%s, nan=%s\n", + + float.MIN.to_string (), + float.MAX.to_string (), + + float.MANT_DIG.to_string (), + float.DIG.to_string (), + float.MIN_EXP.to_string (), + float.MAX_EXP.to_string (), + float.MIN_10_EXP.to_string (), + float.MAX_10_EXP.to_string (), + + float.EPSILON.to_string (), + float.INFINITY.to_string (), + (-float.INFINITY).to_string (), + float.NAN.to_string ()); + + for (int i = 0; i < 6; i++) { // XXX use foreach + float value = FLOAT_TESTS[i]; + int infinity = value.is_infinity (); + + stdout.printf ( + "float(%g): nan=%s, finite=%s, normal=%s, infinity=%s\n", + + value, + value.is_nan () ? "true" : "false", + value.is_finite () ? "true" : "false", + value.is_normal () ? "true" : "false", + + infinity > 0 ? "positive" : + infinity < 0 ? "negative" : "none"); + } + + stdout.printf ( + "double: range=%s...%s\n" + + " digits=%s(%s), exp=%s..%s(%s..%s)\n" + + " epsilon=%s, infinity=%s/%s, nan=%s\n", + + double.MIN.to_string (), + double.MAX.to_string (), + + double.MANT_DIG.to_string (), + double.DIG.to_string (), + double.MIN_EXP.to_string (), + double.MAX_EXP.to_string (), + double.MIN_10_EXP.to_string (), + double.MAX_10_EXP.to_string (), + + double.EPSILON.to_string (), + double.INFINITY.to_string (), + (-double.INFINITY).to_string (), + double.NAN.to_string ()); + + for (int i = 0; i < 6; i++) { // XXX use foreach + double value = DOUBLE_TESTS[i]; + int infinity = value.is_infinity (); + + stdout.printf( + "double(%g): nan=%s, finite=%s, normal=%s, infinity=%s\n", + + value, + value.is_nan () ? "true" : "false", + value.is_finite () ? "true" : "false", + value.is_normal () ? "true" : "false", + + infinity > 0 ? "positive" : + infinity < 0 ? "negative" : "none"); + } + } +} diff --git a/vala/tests/testrunner.sh b/vala/tests/testrunner.sh index e6f93c0..b9e82c0 100755 --- a/vala/tests/testrunner.sh +++ b/vala/tests/testrunner.sh @@ -25,8 +25,9 @@ topbuilddir=$builddir/.. vapidir=$topbuilddir/vapi VALAC=$topbuilddir/compiler/valac -CC=gcc +CC="gcc -std=c99" CFLAGS="-O0 -g3" +LDLIBS="-lm" CODE=0 @@ -38,7 +39,7 @@ do CODE=1 continue fi - if ! $CC $CFLAGS $(pkg-config --cflags --libs gobject-2.0) -o $testcase $testcase.c > $testcase.err 2>&1 + if ! $CC $CFLAGS $(pkg-config --cflags --libs gobject-2.0) $LDLIBS -o $testcase $testcase.c > $testcase.err 2>&1 then CODE=1 continue diff --git a/vala/vapi/glib-2.0.vala b/vala/vapi/glib-2.0.vala index 93df57a..9034468 100644 --- a/vala/vapi/glib-2.0.vala +++ b/vala/vapi/glib-2.0.vala @@ -33,7 +33,7 @@ public struct pointer { public struct constpointer { } -[CCode (cheader_filename = "glib.h", type_id = "G_TYPE_CHAR", marshaller_type_name = "CHAR", get_value_function = "g_value_get_char", set_value_function = "g_value_set_char")] +[CCode (cname = "gchar", cheader_filename = "glib.h", type_id = "G_TYPE_CHAR", marshaller_type_name = "CHAR", get_value_function = "g_value_get_char", set_value_function = "g_value_set_char")] [IntegerType (rank = 1)] public struct char { [InstanceLast ()] @@ -41,7 +41,7 @@ public struct char { public ref string! to_string (string! format = "%hhi"); } -[CCode (cname = "unsigned char", cheader_filename = "glib.h", type_id = "G_TYPE_UCHAR", marshaller_type_name = "UCHAR", get_value_function = "g_value_get_uchar", set_value_function = "g_value_set_uchar")] +[CCode (cname = "guchar", cheader_filename = "glib.h", type_id = "G_TYPE_UCHAR", marshaller_type_name = "UCHAR", get_value_function = "g_value_get_uchar", set_value_function = "g_value_set_uchar")] [IntegerType (rank = 2)] public struct uchar { [InstanceLast ()] @@ -49,102 +49,271 @@ public struct uchar { public ref string! to_string (string! format = "%hhu"); } -[CCode (cheader_filename = "glib.h", type_id = "G_TYPE_INT", marshaller_type_name = "INT", get_value_function = "g_value_get_int", set_value_function = "g_value_set_int")] -[IntegerType (rank = 7)] +[CCode (cname = "gint", cheader_filename = "glib.h", type_id = "G_TYPE_INT", marshaller_type_name = "INT", get_value_function = "g_value_get_int", set_value_function = "g_value_set_int")] +[IntegerType (rank = 9)] public struct int { + [CCode (cname = "G_MININT")] + public static int MIN; + [CCode (cname = "G_MAXINT")] + public static int MAX; + [InstanceLast ()] [CCode (cname = "g_strdup_printf")] public ref string! to_string (string! format = "%i"); } -[CCode (cname = "unsigned int", cheader_filename = "glib.h", type_id = "G_TYPE_UINT", marshaller_type_name = "UINT", get_value_function = "g_value_get_uint", set_value_function = "g_value_set_uint")] -[IntegerType (rank = 8)] +[CCode (cname = "guint", cheader_filename = "glib.h", type_id = "G_TYPE_UINT", marshaller_type_name = "UINT", get_value_function = "g_value_get_uint", set_value_function = "g_value_set_uint")] +[IntegerType (rank = 10)] public struct uint { + [CCode (cname = "0")] + public static uint MIN; + [CCode (cname = "G_MAXUINT")] + public static uint MAX; + [InstanceLast ()] [CCode (cname = "g_strdup_printf")] public ref string! to_string (string! format = "%u"); } -[CCode (cheader_filename = "glib.h")] -[IntegerType (rank = 3)] +[CCode (cname = "gshort", cheader_filename = "glib.h")] +[IntegerType (rank = 5)] public struct short { + [CCode (cname = "G_MINSHORT")] + public static short MIN; + [CCode (cname = "G_MAXSHORT")] + public static short MAX; + [InstanceLast ()] [CCode (cname = "g_strdup_printf")] public ref string! to_string (string! format = "%hi"); } -[CCode (cname = "unsigned short", cheader_filename = "glib.h")] -[IntegerType (rank = 4)] +[CCode (cname = "gushort", cheader_filename = "glib.h")] +[IntegerType (rank = 6)] public struct ushort { + [CCode (cname = "0U")] + public static ushort MIN; + [CCode (cname = "G_MAXUSHORT")] + public static ushort MAX; + [InstanceLast ()] [CCode (cname = "g_strdup_printf")] public ref string! to_string (string! format = "%hu"); } -[CCode (cheader_filename = "glib.h", type_id = "G_TYPE_LONG", marshaller_type_name = "LONG", get_value_function = "g_value_get_long", set_value_function = "g_value_set_long")] -[IntegerType (rank = 12)] +[CCode (cname = "glong", cheader_filename = "glib.h", type_id = "G_TYPE_LONG", marshaller_type_name = "LONG", get_value_function = "g_value_get_long", set_value_function = "g_value_set_long")] +[IntegerType (rank = 14)] public struct long { + [CCode (cname = "G_MINLONG")] + public static long MIN; + [CCode (cname = "G_MAXLONG")] + public static long MAX; + [InstanceLast ()] [CCode (cname = "g_strdup_printf")] public ref string! to_string (string! format = "%li"); } -[CCode (cname = "unsigned long", cheader_filename = "glib.h", type_id = "G_TYPE_ULONG", marshaller_type_name = "ULONG", get_value_function = "g_value_get_ulong", set_value_function = "g_value_set_ulong")] -[IntegerType (rank = 13)] +[CCode (cname = "gulong", cheader_filename = "glib.h", type_id = "G_TYPE_ULONG", marshaller_type_name = "ULONG", get_value_function = "g_value_get_ulong", set_value_function = "g_value_set_ulong")] +[IntegerType (rank = 15)] public struct ulong { + [CCode (cname = "0UL")] + public static ulong MIN; + [CCode (cname = "G_MAXULONG")] + public static ulong MAX; + [InstanceLast ()] [CCode (cname = "g_strdup_printf")] public ref string! to_string (string! format = "%lu"); } +[CCode (cname = "gint8", cheader_filename = "glib.h", type_id = "G_TYPE_CHAR", marshaller_type_name = "CHAR", get_value_function = "g_value_get_char", set_value_function = "g_value_set_char")] +[IntegerType (rank = 3)] +public struct int8 { + [CCode (cname = "G_MININT8")] + public static int8 MIN; + [CCode (cname = "G_MAXINT8")] + public static int8 MAX; + + [CCode (cname = "g_strdup_printf"), InstanceLast] + public string! to_string (string! format = "%i"); +} + +[CCode (cname = "guint8", cheader_filename = "glib.h")] +[IntegerType (rank = 4)] +public struct uint8 { + [CCode (cname = "0U")] + public static uint8 MIN; + [CCode (cname = "G_MAXUINT8")] + public static uint8 MAX; + + [CCode (cname = "g_strdup_printf"), InstanceLast] + public ref string! to_string (string! format = "%u"); +} + [CCode (cname = "gint16", cheader_filename = "glib.h")] -[IntegerType (rank = 5)] +[IntegerType (rank = 7)] public struct int16 { + [CCode (cname = "G_MININT16")] + public static int16 MIN; + [CCode (cname = "G_MAXINT16")] + public static int16 MAX; + + [CCode (cname = "g_strdup_printf"), InstanceLast] + public ref string! to_string (string! format = "%i"); } [CCode (cname = "guint16", cheader_filename = "glib.h")] -[IntegerType (rank = 6)] +[IntegerType (rank = 8)] public struct uint16 { + [CCode (cname = "0U")] + public static uint16 MIN; + [CCode (cname = "G_MAXUINT16")] + public static uint16 MAX; + + [CCode (cname = "g_strdup_printf"), InstanceLast] + public ref string! to_string (string! format = "%u"); } [CCode (cname = "gint32", cheader_filename = "glib.h")] -[IntegerType (rank = 9)] +[IntegerType (rank = 11)] public struct int32 { + [CCode (cname = "G_MININT32")] + public static int32 MIN; + [CCode (cname = "G_MAXINT32")] + public static int32 MAX; + + [CCode (cname = "g_strdup_printf"), InstanceLast] + public ref string! to_string (string! format = "%li"); } [CCode (cname = "guint32", cheader_filename = "glib.h")] -[IntegerType (rank = 10)] +[IntegerType (rank = 12)] public struct uint32 { + [CCode (cname = "0U")] + public static uint32 MIN; + [CCode (cname = "G_MAXUINT32")] + public static uint32 MAX; + + [InstanceLast ()] + [CCode (cname = "g_strdup_printf")] + public ref string! to_string (string! format = "%lu"); } [CCode (cname = "gint64", cheader_filename = "glib.h", type_id = "G_TYPE_INT64", marshaller_type_name = "INT64", get_value_function = "g_value_get_int64", set_value_function = "g_value_set_int64")] -[IntegerType (rank = 14)] +[IntegerType (rank = 16)] public struct int64 { + [CCode (cname = "G_MININT64")] + public static int64 MIN; + [CCode (cname = "G_MAXINT64")] + public static int64 MAX; + [InstanceLast ()] [CCode (cname = "g_strdup_printf")] public ref string! to_string (string! format = "%lli"); } [CCode (cname = "guint64", cheader_filename = "glib.h", type_id = "G_TYPE_UINT64", marshaller_type_name = "UINT64", get_value_function = "g_value_get_uint64", set_value_function = "g_value_set_uint64")] -[IntegerType (rank = 15)] +[IntegerType (rank = 17)] public struct uint64 { + [CCode (cname = "0ULL")] + public static uint64 MIN; + [CCode (cname = "G_MAXUINT64")] + public static uint64 MAX; + [InstanceLast ()] [CCode (cname = "g_strdup_printf")] public ref string! to_string (string! format = "%llu"); } -[CCode (cname = "float", cheader_filename = "glib.h", type_id = "G_TYPE_FLOAT", marshaller_type_name = "FLOAT", get_value_function = "g_value_get_float", set_value_function = "g_value_set_float")] +[CCode (cname = "float", cheader_filename = "glib.h,float.h,math.h", type_id = "G_TYPE_FLOAT", marshaller_type_name = "FLOAT", get_value_function = "g_value_get_float", set_value_function = "g_value_set_float")] [FloatingType (rank = 1)] public struct float { + [CCode (cname = "FLT_MANT_DIG")] + public static int MANT_DIG; + [CCode (cname = "FLT_DIG")] + public static int DIG; + + [CCode (cname = "FLT_MIN_EXP")] + public static int MIN_EXP; + [CCode (cname = "FLT_MAX_EXP")] + public static int MAX_EXP; + + [CCode (cname = "FLT_MIN_10_EXP")] + public static int MIN_10_EXP; + [CCode (cname = "FLT_MAX_10_EXP")] + public static int MAX_10_EXP; + + [CCode (cname = "FLT_EPSILON")] + public static float EPSILON; + [CCode (cname = "FLT_MIN")] + public static float MIN; + [CCode (cname = "FLT_MAX")] + public static float MAX; + + [CCode (cname = "NAN")] + public static float NAN; + [CCode (cname = "INFINITY")] + public static float INFINITY; + + [CCode (cname = "isnan")] + public bool is_nan (); + [CCode (cname = "isfinite")] + public bool is_finite (); + [CCode (cname = "isnormal")] + public bool is_normal (); + [CCode (cname = "isinf")] + public int is_infinity (); + + [CCode (cname = "g_strdup_printf"), InstanceLast] + public ref string! to_string (string! format = "%g"); } -[CCode (cname = "double", cheader_filename = "glib.h", type_id = "G_TYPE_DOUBLE", marshaller_type_name = "DOUBLE", get_value_function = "g_value_get_double", set_value_function = "g_value_set_double")] +[CCode (cname = "double", cheader_filename = "glib.h,float.h,math.h", type_id = "G_TYPE_DOUBLE", marshaller_type_name = "DOUBLE", get_value_function = "g_value_get_double", set_value_function = "g_value_set_double")] [FloatingType (rank = 2)] public struct double { + [CCode (cname = "DBL_MANT_DIG")] + public static int MANT_DIG; + [CCode (cname = "DBL_DIG")] + public static int DIG; + + [CCode (cname = "DBL_MIN_EXP")] + public static int MIN_EXP; + [CCode (cname = "DBL_MAX_EXP")] + public static int MAX_EXP; + + [CCode (cname = "DBL_MIN_10_EXP")] + public static int MIN_10_EXP; + [CCode (cname = "DBL_MAX_10_EXP")] + public static int MAX_10_EXP; + + [CCode (cname = "DBL_EPSILON")] + public static double EPSILON; + [CCode (cname = "DBL_MIN")] + public static double MIN; + [CCode (cname = "DBL_MAX")] + public static double MAX; + + [CCode (cname = "((double) NAN)")] + public static double NAN; + [CCode (cname = "((double) INFINITY)")] + public static double INFINITY; + + [CCode (cname = "isnan")] + public bool is_nan (); + [CCode (cname = "isfinite")] + public bool is_finite (); + [CCode (cname = "isnormal")] + public bool is_normal (); + [CCode (cname = "isinf")] + public int is_infinity (); + + [CCode (cname = "g_strdup_printf"), InstanceLast] + public ref string! to_string (string! format = "%g"); } [CCode (cname = "gunichar", cheader_filename = "glib.h", get_value_function = "g_value_get_int", set_value_function = "g_value_set_int")] -[IntegerType (rank = 11)] +[IntegerType (rank = 13)] public struct unichar { [CCode (cname = "g_unichar_isalnum")] public bool isalnum ();