2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / libjava / java / lang / natMath.cc
blob1903e27b38fcbb0edd7df2a0f5ec137c436ec827
1 /* Copyright (C) 1998, 1999, 2000, 2002 Free Software Foundation
3 This file is part of libgcj.
5 This software is copyrighted work licensed under the terms of the
6 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
7 details. */
9 /**
10 * @author Andrew Haley <aph@cygnus.com>
11 * @date Tue Sep 22 1998 */
12 /* Written using "Java Class Libraries", 2nd edition, ISBN 0-201-31002-3
13 * "The Java Language Specification", ISBN 0-201-63451-1
14 * plus online API docs for JDK 1.2 beta from http://www.javasoft.com.
15 * Status: Believed complete and correct.
18 #include <config.h>
20 #include <java/lang/String.h>
21 #include <java/lang/Float.h>
22 #include <java/lang/Double.h>
23 #include <java/lang/Integer.h>
24 #include <java/lang/Long.h>
25 #include <java/lang/Math.h>
26 #include <gcj/array.h>
28 #include "fdlibm.h"
30 jdouble java::lang::Math::cos(jdouble x)
32 return (jdouble)::cos((double)x);
35 jdouble java::lang::Math::sin(jdouble x)
37 return (jdouble)::sin((double)x);
40 jdouble java::lang::Math::tan(jdouble x)
42 return (jdouble)::tan((double)x);
45 jdouble java::lang::Math::asin(jdouble x)
47 return (jdouble)::asin((double)x);
50 jdouble java::lang::Math::acos(jdouble x)
52 return (jdouble)::acos((double)x);
55 jdouble java::lang::Math::atan(jdouble x)
57 return (jdouble)::atan((double)x);
60 jdouble java::lang::Math::atan2(jdouble y, jdouble x)
62 return (jdouble)::atan2((double)y, (double)x);
65 jdouble java::lang::Math::log(jdouble x)
67 return (jdouble)::log((double)x);
70 jdouble java::lang::Math::exp(jdouble x)
72 return (jdouble)::exp((double)x);
75 jdouble java::lang::Math::sqrt(jdouble x)
77 return (jdouble)::sqrt((double)x);
80 jdouble java::lang::Math::pow(jdouble y, jdouble x)
82 return (jdouble)::pow((double)y, (double)x);
85 jdouble java::lang::Math::IEEEremainder(jdouble y, jdouble x)
87 return (jdouble)::__ieee754_remainder((double)y, (double)x);
90 jdouble java::lang::Math::rint(jdouble x)
92 return (jdouble)::rint((double)x);
95 jdouble java::lang::Math::floor(jdouble x)
97 return (jdouble)::floor((double)x);
100 jdouble java::lang::Math::ceil(jdouble x)
102 return (jdouble)::ceil((double)x);
105 static inline int
106 floatToIntBits (jfloat value)
108 union {
109 jint l;
110 jfloat d;
111 } u;
112 u.d = value;
113 return u.l;
116 static inline bool
117 isNaN (jint bits)
119 jint e = bits & 0x7f800000;
120 jint f = bits & 0x007fffff;
122 return e == 0x7f800000 && f != 0;
125 static inline jlong
126 doubleToLongBits (jdouble value)
128 union {
129 jlong l;
130 jdouble d;
131 } u;
132 u.d = value;
133 return u.l;
136 static inline bool
137 isNaN (jlong bits)
139 jlong e = bits & 0x7ff0000000000000LL;
140 jlong f = bits & 0x000fffffffffffffLL;
142 return e == 0x7ff0000000000000LL && f != 0LL;