[pure-lang-svn] SF.net SVN: pure-lang:[496] pure/trunk
Status: Beta
Brought to you by:
agraef
|
From: <ag...@us...> - 2008-08-14 13:37:07
|
Revision: 496
http://pure-lang.svn.sourceforge.net/pure-lang/?rev=496&view=rev
Author: agraef
Date: 2008-08-14 13:37:16 +0000 (Thu, 14 Aug 2008)
Log Message:
-----------
Added ubyte, ushort, uint, ulong routines to convert integers to unsigned quantities, as discussed on the mailing list.
Modified Paths:
--------------
pure/trunk/ChangeLog
pure/trunk/lib/primitives.pure
Modified: pure/trunk/ChangeLog
===================================================================
--- pure/trunk/ChangeLog 2008-08-14 13:03:22 UTC (rev 495)
+++ pure/trunk/ChangeLog 2008-08-14 13:37:16 UTC (rev 496)
@@ -1,5 +1,9 @@
2008-08-14 Albert Graef <Dr....@t-...>
+ * lib/primitives.pure: Added routines to convert signed integers
+ to the corresponding unsigned quantities, as discussed on the
+ mailing list.
+
* lib/math.pure: Bugfixes, overhaul of number predicates, added
missing semantic number predicates.
Modified: pure/trunk/lib/primitives.pure
===================================================================
--- pure/trunk/lib/primitives.pure 2008-08-14 13:03:22 UTC (rev 495)
+++ pure/trunk/lib/primitives.pure 2008-08-14 13:37:16 UTC (rev 496)
@@ -91,6 +91,21 @@
pointer x::double |
pointer x::string = pure_pointerval x;
+/* Convert signed (8/16/32/64) bit integers to the corresponding unsigned
+ quantities. These functions behave as if the value was "cast" to the
+ corresponding unsigned C type, and are most useful for dealing with
+ unsigned integers returned by external C routines. The routines always use
+ the smallest Pure int type capable of holding the result: int for ubyte and
+ ushort, bigint for uint and ulong. (Note that in the case of 64 bit values
+ the C interface returns a bigint, that's why ulong takes a bigint
+ parameter. The other routines all take an int as input.) */
+
+ubyte x::int = if x>=0 then x else x+0x100;
+ushort x::int = if x>=0 then x else x+0x10000;
+uint x::int = if x>=0 then bigint x else x+0x100000000L;
+ulong x::bigint = if x>=0 then x else x+0x10000000000000000L;
+
+
/* Absolute value and sign of a number. */
abs x::int | abs x::bigint | abs x::double
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|