[Mathlib-commitlog] SF.net SVN: mathlib:[653] JMathLib/trunk/src/jmathlib/toolbox/general/ uint32.j
Status: Beta
Brought to you by:
st_mueller
|
From: <st_...@us...> - 2009-01-08 19:41:01
|
Revision: 653
http://mathlib.svn.sourceforge.net/mathlib/?rev=653&view=rev
Author: st_mueller
Date: 2009-01-08 19:40:57 +0000 (Thu, 08 Jan 2009)
Log Message:
-----------
new file for uint32 variables
Added Paths:
-----------
JMathLib/trunk/src/jmathlib/toolbox/general/uint32.java
Added: JMathLib/trunk/src/jmathlib/toolbox/general/uint32.java
===================================================================
--- JMathLib/trunk/src/jmathlib/toolbox/general/uint32.java (rev 0)
+++ JMathLib/trunk/src/jmathlib/toolbox/general/uint32.java 2009-01-08 19:40:57 UTC (rev 653)
@@ -0,0 +1,81 @@
+package jmathlib.toolbox.general;
+
+import jmathlib.core.tokens.*;
+import jmathlib.core.tokens.numbertokens.*;
+import jmathlib.core.functions.ExternalFunction;
+
+public class uint32 extends ExternalFunction
+{
+ public OperandToken evaluate(Token[] operands)
+ {
+
+ if (getNArgIn(operands) != 1 )
+ throwMathLibException("uint32: number of arguments !=1");
+
+ if (!(operands[0] instanceof DoubleNumberToken))
+ throwMathLibException("uint32: only works on numbers");
+
+ DoubleNumberToken num = (DoubleNumberToken)operands[0];
+
+ int[] size = num.getSize();
+
+ int n = num.getNumberOfElements();
+
+ UInt32NumberToken uint32 = new UInt32NumberToken(size, null, null);
+
+ double re = 0;
+ double im = 0;
+ int reI = 0;
+ int imI = 0;
+ for (int i=0; i<n; i++)
+ {
+
+ re = num.getValueRe(i);
+ im = num.getValueIm(i);
+
+ if (re>65535)
+ reI = 65535;
+ else if (re<0)
+ reI = 0;
+ else
+ reI = (int)re;
+
+ if (im>65535)
+ imI = 65535;
+ else if (im<0)
+ imI = 0;
+ else
+ imI = (int)im;
+
+ uint32.setValue(i, reI, imI);
+
+ }
+
+ return uint32;
+
+ } // end eval
+}
+
+/*
+@GROUP
+general
+@SYNTAX
+uint32(x)
+@DOC
+converts a double array into an array of uint8 (range 0 up to +255)
+@EXAMPLES
+<programlisting>
+
+</programlisting>
+@SEE
+double, int16, int8, uint8, uint16
+*/
+
+/*
+%!@testcase
+%! ml.executeExpression("a=uint32(88);");
+%! ml.executeExpression("b=class(a);");
+%! assertEquals( "uint32", ml.getString("b"));
+%!
+*/
+
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|