All JavaScript numbers will have doubleValue__D and co. methods. One can also use valueOf() on any Number to get its primitive value
2 * Copyright (c) 1994, 2001, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
28 import org.apidesign.bck2brwsr.core.ExtraJavaScript;
29 import org.apidesign.bck2brwsr.core.JavaScriptBody;
30 import org.apidesign.bck2brwsr.core.JavaScriptOnly;
31 import org.apidesign.bck2brwsr.core.JavaScriptPrototype;
34 * The abstract class <code>Number</code> is the superclass of classes
35 * <code>BigDecimal</code>, <code>BigInteger</code>,
36 * <code>Byte</code>, <code>Double</code>, <code>Float</code>,
37 * <code>Integer</code>, <code>Long</code>, and <code>Short</code>.
39 * Subclasses of <code>Number</code> must provide methods to convert
40 * the represented numeric value to <code>byte</code>, <code>double</code>,
41 * <code>float</code>, <code>int</code>, <code>long</code>, and
45 * @author Arthur van Hoff
47 * @see java.lang.Double
48 * @see java.lang.Float
49 * @see java.lang.Integer
51 * @see java.lang.Short
55 resource="/org/apidesign/vm4brwsr/emul/lang/java_lang_Number.js",
58 @JavaScriptPrototype(container = "Number.prototype", prototype = "new Number")
59 public abstract class Number implements java.io.Serializable {
61 * Returns the value of the specified number as an <code>int</code>.
62 * This may involve rounding or truncation.
64 * @return the numeric value represented by this object after conversion
65 * to type <code>int</code>.
67 @JavaScriptBody(args = {}, body = "return this | 0;")
68 public abstract int intValue();
71 * Returns the value of the specified number as a <code>long</code>.
72 * This may involve rounding or truncation.
74 * @return the numeric value represented by this object after conversion
75 * to type <code>long</code>.
77 @JavaScriptBody(args = {}, body = "return this.toLong();")
78 public abstract long longValue();
81 * Returns the value of the specified number as a <code>float</code>.
82 * This may involve rounding.
84 * @return the numeric value represented by this object after conversion
85 * to type <code>float</code>.
87 @JavaScriptBody(args = {}, body = "return this;")
88 public abstract float floatValue();
91 * Returns the value of the specified number as a <code>double</code>.
92 * This may involve rounding.
94 * @return the numeric value represented by this object after conversion
95 * to type <code>double</code>.
97 @JavaScriptBody(args = {}, body = "return this;")
98 public abstract double doubleValue();
101 * Returns the value of the specified number as a <code>byte</code>.
102 * This may involve rounding or truncation.
104 * @return the numeric value represented by this object after conversion
105 * to type <code>byte</code>.
108 public byte byteValue() {
109 return (byte)intValue();
113 * Returns the value of the specified number as a <code>short</code>.
114 * This may involve rounding or truncation.
116 * @return the numeric value represented by this object after conversion
117 * to type <code>short</code>.
120 public short shortValue() {
121 return (short)intValue();
124 /** use serialVersionUID from JDK 1.0.2 for interoperability */
125 private static final long serialVersionUID = -8742448824652078965L;
128 // as last step of initialization, initialize valueOf method
131 @JavaScriptBody(args = { }, body =
132 "var p = vm.java_lang_Number(false);\n" +
133 "p.valueOf = function() { return this.doubleValue__D(); };\n" +
134 "p.toString = function() { return this.toString__Ljava_lang_String_2(); };"
136 private native static void initValueOf();