[Nice-commit] Nice/stdlib/nice/lang numeric.nice,1.23,1.24
Brought to you by:
bonniot
|
From: <bo...@us...> - 2003-04-30 18:56:04
|
Update of /cvsroot/nice/Nice/stdlib/nice/lang
In directory sc8-pr-cvs1:/tmp/cvs-serv24458/stdlib/nice/lang
Modified Files:
numeric.nice
Log Message:
Implemented handling of numeric values as arrays of bits: read access for
all values, and write access for numeric variables and fields.
The implementation uses the new bossa.syntax.Macro interface, which allows
inlined methods to do semantic checks on their arguments.
Index: numeric.nice
===================================================================
RCS file: /cvsroot/nice/Nice/stdlib/nice/lang/numeric.nice,v
retrieving revision 1.23
retrieving revision 1.24
diff -C2 -d -r1.23 -r1.24
*** numeric.nice 18 Apr 2003 15:14:48 -0000 1.23
--- numeric.nice 30 Apr 2003 18:55:29 -0000 1.24
***************
*** 26,35 ****
// Narrowing primitive conversions
! double double(double d) = inline nice.lang.inline.Nop();
! float float(double d) = inline nice.lang.inline.Nop();
! int int(double d) = inline nice.lang.inline.Nop();
! short short(double d) = inline nice.lang.inline.Nop();
! byte byte(double d) = inline nice.lang.inline.Nop();
! char char(double d) = inline nice.lang.inline.Nop();
--- 26,36 ----
// Narrowing primitive conversions
! double double(double) = inline nice.lang.inline.Nop();
! long long (double) = inline nice.lang.inline.Nop();
! float float (double) = inline nice.lang.inline.Nop();
! int int (double) = inline nice.lang.inline.Nop();
! short short (double) = inline nice.lang.inline.Nop();
! byte byte (double) = inline nice.lang.inline.Nop();
! char char (double) = inline nice.lang.inline.Nop();
***************
*** 152,166 ****
****************************************************************/
! // Note: we should have testcases for this section.
! // Upcasts
! long long(int) = inline nice.lang.inline.Nop();
! // Accessing individual bits of a word
! boolean get(long x, int bit) = (x & (long(1) << bit)) != 0;
! boolean get(int x, int bit) = (x & (1 << bit)) != 0;
! /** Returns a random positive number smaller than limit. */
int random(int limit) = int(floor(random() * limit));
--- 153,185 ----
****************************************************************/
! /**
! Get the <code>i</code>th bit of <code>x</code>.
! <code>x</code> can have any numeric type.
! If <code>bit</code> is larger than the number of bits of
! <code>x</code>, this function returns <ocde>false</code>.
+ You can use this function with the array syntax:
+ <code>x[bit]</code>
+ */
+ boolean get(long x, int bit) = inline nice.lang.inline.BitOp("get");
! /**
! Set the <code>i</code>th bit of <code>x</code>
! on if <code>v</code> is <code>true</code>;
! off if <code>v</code> is <code>false</code>.
! <code>x</code> must be assignable (a variable or a field).
!
! <code>x</code> can have any numeric type.
! If <code>bit</code> is larger than the number of bits of
! <code>x</code>, this function has no effect.
!
! You can use this function with the array syntax:
! <code>x[bit] = v</code>
! */
! void set(long x, int bit, boolean v) = inline nice.lang.inline.BitOp("set");
!
! /** Returns a random number such that 0 <= random(limit) < limit. */
int random(int limit) = int(floor(random() * limit));
|