Re: [cp-patches] RFC: StrictMath.tanh implemented
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hi Sven, Sven de Marothy wrote: > On Wed, 2006-08-02 at 20:27 +0200, Carsten Neumann wrote: >> this adds another missing method to StrictMath, mauve test is already in. >> Comments or approval, appreciated. > > Seems just fine to me. Just two minor points: > (This being _strict_ math, after all. ;)) > 1) l_bits is unused. thanks, for spotting this, fixed in the attached. > 2) If a random NaN number is passed in, the JDK returns that number, and > not the NaN constant. This is fixed for tanh in the attached updated version. I'll post a seperate patch to fix this for the other methods I implemented recently. Thanks, Carsten Committed as: 2006-08-03 Carsten Neumann <[EMAIL PROTECTED]> * java/lang/StrictMath.java (tanh): New method. -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.3 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFE0kLGd4NEZjs4PvgRAiHUAJ9zppes1lqzMXtDNVL4uUcoTUuEXACfSRg2 OKEyntgPd0cbQsh25gOiO/M= =4N2h -END PGP SIGNATURE- Index: cp/classpath/java/lang/StrictMath.java === --- cp.orig/classpath/java/lang/StrictMath.java 2006-08-02 19:17:29.0 +0200 +++ cp/classpath/java/lang/StrictMath.java 2006-08-03 19:53:23.0 +0200 @@ -814,6 +814,75 @@ } /** + * Returns the hyperbolic tangent of x, which is defined as + * (exp(x) - exp(-x)) / (exp(x) + exp(-x)), i.e. sinh(x) / cosh(x). + * + Special cases: + * + * If the argument is NaN, the result is NaN + * If the argument is positive infinity, the result is 1. + * If the argument is negative infinity, the result is -1. + * If the argument is zero, the result is zero. + * + * + * @param x the argument to tanh + * @return the hyperbolic tagent of x + * + * @since 1.5 + */ + public static double tanh(double x) + { +// Method : +// 0. tanh(x) is defined to be (exp(x) - exp(-x)) / (exp(x) + exp(-x)) +// 1. reduce x to non-negative by tanh(-x) = -tanh(x). +// 2. 0 <= x <= 2^-55 : tanh(x) := x * (1.0 + x) +//-t +// 2^-55 < x <= 1 : tanh(x) := -; t = expm1(-2x) +// t + 2 +// 2 +// 1 <= x <= 22.0 : tanh(x) := 1 - - ; t=expm1(2x) +//t + 2 +// 22.0 < x <= INF : tanh(x) := 1. + +double t, z; + +long bits; +long h_bits; + +// handle special cases +if (x != x) + return x; +if (x == Double.POSITIVE_INFINITY) + return 1.0; +if (x == Double.NEGATIVE_INFINITY) + return -1.0; + +bits = Double.doubleToLongBits(x); +h_bits = getHighDWord(bits) & 0x7fffL; // ingnore sign + +if (h_bits < 0x4036L) // |x| < 22 + { + if (h_bits < 0x3c80L) // |x| < 2^-55 + return x * (1.0 + x); + + if (h_bits >= 0x3ff0L) // |x| >= 1 + { + t = expm1(2.0 * abs(x)); + z = 1.0 - 2.0 / (t + 2.0); + } + else// |x| < 1 + { + t = expm1(-2.0 * abs(x)); + z = -t / (t + 2.0); + } + } +else// |x| >= 22 + z = 1.0; + +return (x >= 0) ? z : -z; + } + + /** * Returns the lower two words of a long. This is intended to be * used like this: * getLowDWord(Double.doubleToLongBits(x)).
[cp-patches] FYI: StrictMath, fixed NaN handling.
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hi, as Sven pointed out here: http://developer.classpath.org/pipermail/classpath-patches/2006-August/003678.html the methods i recently implemented must return their argument if it is NaN, instead of returning the constant Double.NaN. I took the liberty of committing this without asking for approval, since it's in response to a comment from Sven, trivial and backed by mauve tests. Please start yelling if I leaned too far out of the window. Thanks, Carsten 2006-08-03 Carsten Neumann <[EMAIL PROTECTED]> * StrictMath.java (cbrt): Return argument if it is a NaN. (cosh): Likewise. (expm1): Likewise. (sinh): Likewise. -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.3 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFE0kjPd4NEZjs4PvgRAloyAJ0WwV45gJtH2KCUb+vx/xcq2WXa3QCgxC08 VFC8KJvLhuly3oeZYP8TG3w= =6v1m -END PGP SIGNATURE- Index: java/lang/StrictMath.java === RCS file: /sources/classpath/classpath/java/lang/StrictMath.java,v retrieving revision 1.14 diff -u -r1.14 StrictMath.java --- java/lang/StrictMath.java 3 Aug 2006 18:42:11 - 1.14 +++ java/lang/StrictMath.java 3 Aug 2006 18:47:24 - @@ -673,7 +673,7 @@ // handle special cases if (x != x) - return Double.NaN; + return x; if (x == Double.POSITIVE_INFINITY) return Double.POSITIVE_INFINITY; if (x == Double.NEGATIVE_INFINITY) @@ -763,7 +763,7 @@ // handle special cases if (x != x) - return Double.NaN; + return x; if (x == Double.POSITIVE_INFINITY) return Double.POSITIVE_INFINITY; if (x == Double.NEGATIVE_INFINITY) @@ -947,7 +947,7 @@ // handle the special cases if (x != x) - return Double.NaN; + return x; if (x == Double.POSITIVE_INFINITY) return Double.POSITIVE_INFINITY; if (x == Double.NEGATIVE_INFINITY) @@ -1180,7 +1180,7 @@ if (h_bits >= 0x7ff0L) { if (((h_bits & 0x000fL) | (l_bits & 0xL)) != 0) - return Double.NaN; // exp(NaN) = NaN + return x;// exp(NaN) = NaN else return negative ? -1.0 : x; // exp({+-inf}) = {+inf, -1} }
[cp-patches] RFC: StrictMath.tanh implemented
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hi, this adds another missing method to StrictMath, mauve test is already in. Comments or approval, appreciated. Thanks, Carsten 2006-08-02 Carsten Neumann <[EMAIL PROTECTED]> * java/lang/StrictMath.java (tanh): New method. -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.3 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFE0O53d4NEZjs4PvgRAtz+AKCuQVkMcMll46qjaTncnGil0y9dPQCgq3hP 5jC5d6+dETLjqvuhbszf8Ws= =oqg6 -END PGP SIGNATURE- Index: cp/classpath/java/lang/StrictMath.java === --- cp.orig/classpath/java/lang/StrictMath.java 2006-08-02 19:17:29.0 +0200 +++ cp/classpath/java/lang/StrictMath.java 2006-08-02 19:21:06.0 +0200 @@ -814,6 +814,77 @@ } /** + * Returns the hyperbolic tangent of x, which is defined as + * (exp(x) - exp(-x)) / (exp(x) + exp(-x)), i.e. sinh(x) / cosh(x). + * + Special cases: + * + * If the argument is NaN, the result is NaN + * If the argument is positive infinity, the result is 1. + * If the argument is negative infinity, the result is -1. + * If the argument is zero, the result is zero. + * + * + * @param x the argument to tanh + * @return the hyperbolic tagent of x + * + * @since 1.5 + */ + public static double tanh(double x) + { +// Method : +// 0. tanh(x) is defined to be (exp(x) - exp(-x)) / (exp(x) + exp(-x)) +// 1. reduce x to non-negative by tanh(-x) = -tanh(x). +// 2. 0 <= x <= 2^-55 : tanh(x) := x * (1.0 + x) +//-t +// 2^-55 < x <= 1 : tanh(x) := -; t = expm1(-2x) +// t + 2 +// 2 +// 1 <= x <= 22.0 : tanh(x) := 1 - - ; t=expm1(2x) +//t + 2 +// 22.0 < x <= INF : tanh(x) := 1. + +double t, z; + +long bits; +long h_bits; +long l_bits; + +// handle special cases +if (x != x) + return Double.NaN; +if (x == Double.POSITIVE_INFINITY) + return 1.0; +if (x == Double.NEGATIVE_INFINITY) + return -1.0; + +bits = Double.doubleToLongBits(x); +h_bits = getHighDWord(bits) & 0x7fffL; // ingnore sign +l_bits = getLowDWord(bits); + +if (h_bits < 0x4036L) // |x| < 22 + { + if (h_bits < 0x3c80L) // |x| < 2^-55 + return x * (1.0 + x); + + if (h_bits >= 0x3ff0L) // |x| >= 1 + { + t = expm1(2.0 * abs(x)); + z = 1.0 - 2.0 / (t + 2.0); + } + else// |x| < 1 + { + t = expm1(-2.0 * abs(x)); + z = -t / (t + 2.0); + } + } +else// |x| >= 22 + z = 1.0; + +return (x >= 0) ? z : -z; + } + + /** * Returns the lower two words of a long. This is intended to be * used like this: * getLowDWord(Double.doubleToLongBits(x)).
Re: [cp-patches] RFC: StrictMath.sinh implemented
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Tom Tromey wrote: >>>>>> "Carsten" == Carsten Neumann <[EMAIL PROTECTED]> writes: > > Carsten> added another method to StrictMath, the mauve tests for this one are > Carsten> already in. > > Go for it. Thanks! committed on 2006-08-02. Thanks, Carsten -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.3 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFE0N2zd4NEZjs4PvgRAvyPAJsFbLRmyx3mGCgUXM+Va5EhUixFQwCgmuos RH1lgryqQjmgC3L9TCer0yM= =9Kn9 -END PGP SIGNATURE-
[cp-patches] RFC: StrictMath.sinh implemented
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hi, added another method to StrictMath, the mauve tests for this one are already in. Comments or approval, appreciated. Thanks, Carsten 2006-07-31 Carsten Neumann <[EMAIL PROTECTED]> * java/lang/StrictMath.java (sinh): New method. -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.3 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFEzk52d4NEZjs4PvgRAnYNAJ9uanGxdCF0iBwIffqtwn5M9Zu54ACfUZCk 5B2fCIfyr6z1muxsprBGtUU= =LVCX -END PGP SIGNATURE- Index: cp/classpath/java/lang/StrictMath.java === --- cp.orig/classpath/java/lang/StrictMath.java 2006-07-29 14:23:04.0 +0200 +++ cp/classpath/java/lang/StrictMath.java 2006-07-31 19:28:31.0 +0200 @@ -633,6 +633,94 @@ } /** + * Returns the hyperbolic sine of x which is defined as + * (exp(x) - exp(-x)) / 2. + * + * Special cases: + * + * If the argument is NaN, the result is NaN + * If the argument is positive infinity, the result is positive + * infinity. + * If the argument is negative infinity, the result is negative + * infinity. + * If the argument is zero, the result is zero. + * + * + * @param x the argument to sinh + * @return the hyperbolic sine of x + * + * @since 1.5 + */ + public static double sinh(double x) + { +// Method : +// mathematically sinh(x) if defined to be (exp(x)-exp(-x))/2 +// 1. Replace x by |x| (sinh(-x) = -sinh(x)). +// 2. +// E + E/(E+1) +// 0 <= x <= 22 : sinh(x) := --, E=expm1(x) +// 2 +// +// 22 <= x <= lnovft : sinh(x) := exp(x)/2 +// lnovft <= x <= ln2ovft: sinh(x) := exp(x/2)/2 * exp(x/2) +// ln2ovft < x : sinh(x) := +inf (overflow) + +double t, w, h; + +long bits; +long h_bits; +long l_bits; + +// handle special cases +if (x != x) + return Double.NaN; +if (x == Double.POSITIVE_INFINITY) + return Double.POSITIVE_INFINITY; +if (x == Double.NEGATIVE_INFINITY) + return Double.NEGATIVE_INFINITY; + +if (x < 0) + h = - 0.5; +else + h = 0.5; + +bits = Double.doubleToLongBits(x); +h_bits = getHighDWord(bits) & 0x7fffL; // ignore sign +l_bits = getLowDWord(bits); + +// |x| in [0, 22], return sign(x) * 0.5 * (E+E/(E+1)) +if (h_bits < 0x4036L) // |x| < 22 + { + if (h_bits < 0x3e30L) // |x| < 2^-28 + return x;// for tiny arguments return x + + t = expm1(abs(x)); + + if (h_bits < 0x3ff0L) + return h * (2.0 * t - t * t / (t + 1.0)); + + return h * (t + t / (t + 1.0)); + } + +// |x| in [22, log(Double.MAX_VALUE)], return 0.5 * exp(|x|) +if (h_bits < 0x40862e42L) + return h * exp(abs(x)); + +// |x| in [log(Double.MAX_VALUE), overflowthreshold] +if ((h_bits < 0x408633ceL) + || ((h_bits == 0x408633ceL) && (l_bits <= 0x8fb9f87dL))) + { + w = exp(0.5 * abs(x)); + t = h * w; + + return t * w; + } + +// |x| > overflowthershold +return h * Double.POSITIVE_INFINITY; + } + + /** * Returns the hyperbolic cosine of x, which is defined as * (exp(x) + exp(-x)) / 2. *
Re: [cp-patches] RFC: StrictMath helper methods "fixed"
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Tom Tromey wrote: >>>>>> "Carsten" == Carsten Neumann <[EMAIL PROTECTED]> writes: > > Carsten> this patch changes the helper methods to deal with the IEEE > Carsten> representation of doubles I introduced with a previous patch > > Carsten> Ok for head ? > > Looks reasonable to me. > At this point I would venture to guess that you know more about your > StrictMath additions than anybody else... oh well, I hope the fdlibm developers are the ones who know it all ;-) Anyway, committed as 2006-07-31 Carsten Neumann <[EMAIL PROTECTED]> * StrictMath.java (getLowDWord): Return long instead of int. (getHighDWord): Likewise. (buildDouble): Take two long arguments. (cbrt): Adapted to int -> long change. (expm1): Likewise. (cosh): Likewise. Thanks, Carsten -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.3 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFEzkW0d4NEZjs4PvgRAjvdAJ41vFzg13pMpgmmzctKK6CN8g6RowCgx3Fw yETsV4zSqK5B2sSUH7V6n1Q= =RwIp -END PGP SIGNATURE-
[cp-patches] RFC: StrictMath helper methods "fixed"
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hi, this patch changes the helper methods to deal with the IEEE representation of doubles I introduced with a previous patch http://developer.classpath.org/pipermail/classpath-patches/2006-July/003369.html The reason for returning a long there is that this allows to do unsigned comparison with constants, which is required e.g. inside cosh and sinh. (This does not fix a bug, it just avoids repeating a mistake that took me quite a while to figure out while testing cosh). Ok for head ? Thanks, Carsten 2006-07-29 Carsten Neumann <[EMAIL PROTECTED]> * StrictMath.java (getLowDWord): Return long instead of int. (getHighDWord): Likewise. (buildDouble): Take two long arguments. (cbrt): Adapted to int -> long change. (expm1): Likewise. (cosh): Likewise. -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.3 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFEyyWYd4NEZjs4PvgRAi2jAKCDuQPSL5KUoWRn3wWd8sOqIFtuSACghjpw QvwSevAve+mHRfU1jUbkACo= =tUaE -END PGP SIGNATURE- Index: java/lang/StrictMath.java === RCS file: /sources/classpath/classpath/java/lang/StrictMath.java,v retrieving revision 1.11 diff -u -r1.11 StrictMath.java --- java/lang/StrictMath.java 26 Jul 2006 19:34:09 - 1.11 +++ java/lang/StrictMath.java 26 Jul 2006 19:56:43 - @@ -670,8 +670,8 @@ double t, w; long bits; -int hx; -int lx; +long hx; +long lx; // handle special cases if (x != x) @@ -682,24 +682,24 @@ return Double.POSITIVE_INFINITY; bits = Double.doubleToLongBits(x); -hx = getHighDWord(bits) & 0x7fff; // ignore sign +hx = getHighDWord(bits) & 0x7fffL; // ignore sign lx = getLowDWord(bits); // |x| in [0, 0.5 * ln(2)], return 1 + expm1(|x|)^2 / (2 * exp(|x|)) -if (hx < 0x3fd62e43) +if (hx < 0x3fd62e43L) { t = expm1(abs(x)); w = 1.0 + t; // for tiny arguments return 1. - if (hx < 0x3c80) + if (hx < 0x3c80L) return w; return 1.0 + (t * t) / (w + w); } // |x| in [0.5 * ln(2), 22], return exp(|x|)/2 + 1 / (2 * exp(|x|)) -if (hx < 0x4036) +if (hx < 0x4036L) { t = exp(abs(x)); @@ -707,16 +707,13 @@ } // |x| in [22, log(Double.MAX_VALUE)], return 0.5 * exp(|x|) -if (hx < 0x40862e42) +if (hx < 0x40862e42L) return 0.5 * exp(abs(x)); // |x| in [log(Double.MAX_VALUE), overflowthreshold], // return exp(x/2)/2 * exp(x/2) - -// we need to force an unsigned <= compare, thus can not use lx. -if ((hx < 0x408633ce) - || ((hx == 0x408633ce) - && ((bits & 0xL) <= 0x8fb9f87dL))) +if ((hx < 0x408633ceL) + || ((hx == 0x408633ceL) && (lx <= 0x8fb9f87dL))) { w = exp(0.5 * abs(x)); t = 0.5 * w; @@ -733,9 +730,9 @@ * used like this: * getLowDWord(Double.doubleToLongBits(x)). */ - private static int getLowDWord(long x) + private static long getLowDWord(long x) { -return (int) (x & 0xL); +return x & 0xL; } /** @@ -743,19 +740,19 @@ * used like this: * getHighDWord(Double.doubleToLongBits(x)). */ - private static int getHighDWord(long x) + private static long getHighDWord(long x) { -return (int) ((x & 0xL) >> 32); +return (x & 0xL) >> 32; } /** * Returns a double with the IEEE754 bit pattern given in the lower * and higher two words lowDWord and highDWord. */ - private static double buildDouble(int lowDWord, int highDWord) + private static double buildDouble(long lowDWord, long highDWord) { -return Double.longBitsToDoublelong) highDWord & 0xL) << 32) - | ((long) lowDWord & 0xL)); +return Double.longBitsToDouble(((highDWord & 0xL) << 32) + | (lowDWord & 0xL)); } /** @@ -788,8 +785,8 @@ double w; long bits; -int l; -int h; +long l; +long h; // handle the special cases if (x != x) @@ -847,7 +844,7 @@ s = t * t; // t * t is exact r = x / s; w = t + t; -r = (r - t) / (w + r); // r - s is exact +r = (r - t) / (w + r); // r - t is exact t = t + t * r; return negative ? -t : t; @@ -1008,8 +1005,8 @@ int k; long bits; -int h_bits; -int l_bits; +long h_bits; +long l_bits; c = 0.0; y = abs(x); @@ -1019,13 +1016,13 @@ l_bits = getLowDWord(bits); // handle special cases and large arguments -if (h_bits >= 0x4043687a)// if |x| >= 56 * ln(2) +if (h_bits >= 0x4043687aL)// if |x| >= 56 * ln(2) { - if
Re: [cp-patches] RFC: StrictMath.expm1 and cosh implemented
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Mark Wielaard wrote: > Hi Carsten, > > On Wed, 2006-07-26 at 18:50 +0200, Carsten Neumann wrote: >>> Anyway I think these StrictMath additions are good, especially seeing >>> as you've written test cases. Great work! >> Thanks. Just to avoid causing offence on my first commit, is this a >> commit approval ? > > Yes, "good", "test cases" and "great work" are Tom slang for > "Please commit this". > ok. committed as 2006-07-26 Carsten Neumann <[EMAIL PROTECTED]> * StrictMath.java (cosh): New method. (expm1): New method. (EXPM1_Q1): New field. (EXPM1_Q2): Likewise. (EXPM1_Q3): Likewise. (EXPM1_Q4): Likewise. (EXPM1_Q6): Likewise. -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.3 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFEx8Pvd4NEZjs4PvgRAlLsAJ0eBAN8BQLT5zqaZdw07rmW6eauRgCgh0k9 ghkk8o8YoDDrv5NbB1FwMbo= =walv -END PGP SIGNATURE-
Re: [cp-patches] RFC: StrictMath.expm1 and cosh implemented
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Tom Tromey wrote: >>>>>> "Carsten" == Carsten Neumann <[EMAIL PROTECTED]> writes: > > Carsten> this implements java.lang.StrictMath.expm1 and cosh functions. > Carsten> Corresponding mauve tests are underway. > Carsten> Please comment/commit. > > Carsten> PS: on 2005-07-22 i already sent the expm1 part of the patch, > Carsten> but this mail never made it to the list appearently; in case > Carsten> it shows up at some point, it should be discarded. > > I'm sure I saw this. I didn't comment since I thought it would be > better to wait until you had commit access. yeah, meanwhile it showed up again in my inbox as well, maybe I should find a new mail service... > Anyway I think these StrictMath additions are good, especially seeing > as you've written test cases. Great work! Thanks. Just to avoid causing offence on my first commit, is this a commit approval ? Thanks, Carsten -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.3 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFEx51cd4NEZjs4PvgRAl9DAKCgWDZM+JS1O/F88c5RrMMAmICLKwCffnmD 3UBrRj7dth77YGXPZJ6LuX0= =Q99v -END PGP SIGNATURE-
[cp-patches] RFC: StrictMath.expm1 and cosh implemented
Hi, this implements java.lang.StrictMath.expm1 and cosh functions. Corresponding mauve tests are underway. Please comment/commit. Thanks, Carsten PS: on 2005-07-22 i already sent the expm1 part of the patch, but this mail never made it to the list appearently; in case it shows up at some point, it should be discarded. 2006-07-24 Carsten Neumann <[EMAIL PROTECTED]> * StrictMath.java (cosh): New method. (expm1): New method. (EXPM1_Q1): New field. (EXPM1_Q2): Likewise. (EXPM1_Q3): Likewise. (EXPM1_Q4): Likewise. (EXPM1_Q6): Likewise. Index: java/lang/StrictMath.java === RCS file: /sources/classpath/classpath/java/lang/StrictMath.java,v retrieving revision 1.10 diff -u -r1.10 StrictMath.java --- java/lang/StrictMath.java 16 Jul 2006 20:23:49 - 1.10 +++ java/lang/StrictMath.java 24 Jul 2006 16:40:03 - @@ -633,6 +633,102 @@ } /** + * Returns the hyperbolic cosine of x, which is defined as + * (exp(x) + exp(-x)) / 2. + * + * Special cases: + * + * If the argument is NaN, the result is NaN + * If the argument is positive infinity, the result is positive + * infinity. + * If the argument is negative infinity, the result is positive + * infinity. + * If the argument is zero, the result is one. + * + * + * @param x the argument to cosh + * @return the hyperbolic cosine of x + * + * @since 1.5 + */ + public static double cosh(double x) + { +// Method : +// mathematically cosh(x) if defined to be (exp(x)+exp(-x))/2 +// 1. Replace x by |x| (cosh(x) = cosh(-x)). +// 2. +// [ exp(x) - 1 ]^2 +// 0<= x <= ln2/2 : cosh(x) := 1 + --- +// 2*exp(x) +// +// exp(x) + 1/exp(x) +// ln2/2<= x <= 22 : cosh(x) := -- +// 2 +// 22 <= x <= lnovft : cosh(x) := exp(x)/2 +// lnovft <= x <= ln2ovft: cosh(x) := exp(x/2)/2 * exp(x/2) +// ln2ovft < x : cosh(x) := +inf (overflow) + +double t, w; +long bits; +int hx; +int lx; + +// handle special cases +if (x != x) + return Double.NaN; +if (x == Double.POSITIVE_INFINITY) + return Double.POSITIVE_INFINITY; +if (x == Double.NEGATIVE_INFINITY) + return Double.POSITIVE_INFINITY; + +bits = Double.doubleToLongBits(x); +hx = getHighDWord(bits) & 0x7fff; // ignore sign +lx = getLowDWord(bits); + +// |x| in [0, 0.5 * ln(2)], return 1 + expm1(|x|)^2 / (2 * exp(|x|)) +if (hx < 0x3fd62e43) + { + t = expm1(abs(x)); + w = 1.0 + t; + + // for tiny arguments return 1. + if (hx < 0x3c80) + return w; + + return 1.0 + (t * t) / (w + w); + } + +// |x| in [0.5 * ln(2), 22], return exp(|x|)/2 + 1 / (2 * exp(|x|)) +if (hx < 0x4036) + { + t = exp(abs(x)); + + return 0.5 * t + 0.5 / t; + } + +// |x| in [22, log(Double.MAX_VALUE)], return 0.5 * exp(|x|) +if (hx < 0x40862e42) + return 0.5 * exp(abs(x)); + +// |x| in [log(Double.MAX_VALUE), overflowthreshold], +// return exp(x/2)/2 * exp(x/2) + +// we need to force an unsigned <= compare, thus can not use lx. +if ((hx < 0x408633ce) + || ((hx == 0x408633ce) + && ((bits & 0xL) <= 0x8fb9f87dL))) + { + w = exp(0.5 * abs(x)); + t = 0.5 * w; + + return t * w; + } + +// |x| > overflowthreshold +return Double.POSITIVE_INFINITY; + } + + /** * Returns the lower two words of a long. This is intended to be * used like this: * getLowDWord(Double.doubleToLongBits(x)). @@ -819,6 +915,254 @@ } /** + * Returns ex - 1. + * Special cases: + * + * If the argument is NaN, the result is NaN. + * If the argument is positive infinity, the result is positive + * infinity + * If the argument is negative infinity, the result is -1. + * If the argument is zero, the result is zero. + * + * + * @param x the argument to ex - 1. + * @return e raised to the power x minus one. + * @see #exp(double) + */ + public static double expm1(double x) + { +// Method +// 1. Argument reduction: +// Given x, find r and integer k such that +// +//x = k * ln(2) + r, |r| <= 0.5 * ln(2) +// +// Here a correction term c will be computed to compensate +// the error in r when rounded to a floating-point number. +// +// 2. Approximating expm1(r) by a special rational function on +// the interval [0, 0.5 * ln(2)]: +// Since +// r*(exp(r)+1)/(exp(r)-1) = 2 + r^2/6 - r^4/360 + ... +// we define R1(r*r) by +// r*(exp(r)+1)/(exp(r)-1) = 2 + r^2/6 * R1(r*
[cp-patches] RFC: StrictMath.expm1 implemented
Hi, this adds the expm1 method to java.lang.StrictMath. Please comment/commit. Thanks, Carsten 2006-07-22 Carsten Neumann <[EMAIL PROTECTED]> * StrictMath.java (expm1): New method. (EXPM1_Q1): New field. (EXPM1_Q2): Likewise. (EXPM1_Q3): Likewise. (EXPM1_Q4): Likewise. (EXPM1_Q6): Likewise. Index: java/lang/StrictMath.java === RCS file: /sources/classpath/classpath/java/lang/StrictMath.java,v retrieving revision 1.10 diff -u -r1.10 StrictMath.java --- java/lang/StrictMath.java 16 Jul 2006 20:23:49 - 1.10 +++ java/lang/StrictMath.java 22 Jul 2006 14:50:39 - @@ -819,6 +819,254 @@ } /** + * Returns ex - 1. + * Special cases: + * + * If the argument is NaN, the result is NaN. + * If the argument is positive infinity, the result is positive + * infinity + * If the argument is negative infinity, the result is -1. + * If the argument is zero, the result is zero. + * + * + * @param x the argument to ex - 1. + * @return e raised to the power x minus one. + * @see #exp(double) + */ + public static double expm1(double x) + { +// Method +// 1. Argument reduction: +// Given x, find r and integer k such that +// +//x = k * ln(2) + r, |r| <= 0.5 * ln(2) +// +// Here a correction term c will be computed to compensate +// the error in r when rounded to a floating-point number. +// +// 2. Approximating expm1(r) by a special rational function on +// the interval [0, 0.5 * ln(2)]: +// Since +// r*(exp(r)+1)/(exp(r)-1) = 2 + r^2/6 - r^4/360 + ... +// we define R1(r*r) by +// r*(exp(r)+1)/(exp(r)-1) = 2 + r^2/6 * R1(r*r) +// That is, +// R1(r**2) = 6/r *((exp(r)+1)/(exp(r)-1) - 2/r) +// = 6/r * ( 1 + 2.0*(1/(exp(r)-1) - 1/r)) +// = 1 - r^2/60 + r^4/2520 - r^6/100800 + ... +// We use a special Remes algorithm on [0, 0.347] to generate +// a polynomial of degree 5 in r*r to approximate R1. The +// maximum error of this polynomial approximation is bounded +// by 2**-61. In other words, +// R1(z) ~ 1.0 + Q1*z + Q2*z**2 + Q3*z**3 + Q4*z**4 + Q5*z**5 +// where Q1 = -1.6567384E-2, +// Q2 = 3.9682539681370365873E-4, +// Q3 = -9.9206344733435987357E-6, +// Q4 = 2.5051361420808517002E-7, +// Q5 = -6.2843505682382617102E-9; +// (where z=r*r, and Q1 to Q5 are called EXPM1_Qx in the source) +// with error bounded by +// | 5 | -61 +// | 1.0+Q1*z+...+Q5*z - R1(z) | <= 2 +// | | +// +// expm1(r) = exp(r)-1 is then computed by the following +// specific way which minimize the accumulation rounding error: +// 2 3 +// r r[ 3 - (R1 + R1*r/2) ] +// expm1(r) = r + --- + --- * [] +// 2 2[ 6 - r*(3 - R1*r/2) ] +// +// To compensate the error in the argument reduction, we use +// expm1(r+c) = expm1(r) + c + expm1(r)*c +// ~ expm1(r) + c + r*c +// Thus c+r*c will be added in as the correction terms for +// expm1(r+c). Now rearrange the term to avoid optimization +// screw up: +// ( 22 ) +// ({ ( r[ R1 - (3 - R1*r/2) ] ) }r ) +// expm1(r+c)~r - ({r*(--- * []-c)-c} - --- ) +// ({ ( 2[ 6 - r*(3 - R1*r/2) ] ) }2 ) +// ( ) +// +// = r - E +// 3. Scale back to obtain expm1(x): +// From step 1, we have +// expm1(x) = either 2^k*[expm1(r)+1] - 1 +// = or 2^k*[expm1(r) + (1-2^-k)] +// 4. Implementation notes: +// (A). To save one multiplication, we scale the coefficient Qi +// to Qi*2^i, and replace z by (x^2)/2. +// (B). To achieve maximum accuracy, we compute expm1(x) by +// (i) if x < -56*ln2, return -1.0, (raise inexact if x!=inf) +// (ii) if k=0, return r-E +// (iii) if k=-1, return 0.5*(r-E)-0.5 +//(iv) if k=1 if r < -0.25, return 2*((r+0.5)- E) +// else return 1.0+2.0*(r-E); +// (v) if (k<-2||k>56) return 2^k(1-(E-r)) - 1 (or exp(x)-1) +// (vi) if k <= 20, return 2^k((1-2^-k)-(E-r)), else +// (vii) return 2^k(1-((E+2^-k)-r)) + +boolean negative = (x < 0); +double y, hi, lo, c, t, e, hxs, hfx, r1; +int k; + +long bits; +int h_bits; +int l_bits; + +c = 0.0; +y = abs(x); + +bits = Double.doubleToLongBits(y); +h_bits = getHighDWord(bits); +l_bits = getLowDWord(bits); + +// handle special cases and large arguments
[cp-patches] RFC: [generics] CopyOnWriteArrayList.java more small fixes
Hi, another set of small fixes for java.util.concurrent.CopyOnWriteArrayList.java Please comment/commit. Thanks, Carsten 2006-07-22 Carsten Neumann <[EMAIL PROTECTED]> * CopyOnWriteArrayList.java: Fixed some API docs. (serialVersionUID): New field. (CopyOnWriteArrayList(E[])): New constructor. Index: java/util/concurrent/CopyOnWriteArrayList.java === RCS file: /sources/classpath/classpath/java/util/concurrent/Attic/CopyOnWriteArrayList.java,v retrieving revision 1.1.2.2 diff -u -r1.1.2.2 CopyOnWriteArrayList.java --- java/util/concurrent/CopyOnWriteArrayList.java 21 Jul 2006 22:41:54 - 1.1.2.2 +++ java/util/concurrent/CopyOnWriteArrayList.java 22 Jul 2006 19:16:14 - @@ -53,12 +53,17 @@ List, RandomAccess, Cloneable, Serializable { /** + * Compatible with JDK 1.5 + */ + private static final long serialVersionUID = 8673264195747942595L; + + /** * Where the data is stored. */ private transient E[] data; /** - * Construct a new ArrayList with the default capacity (16). + * Construct a new empty CopyOnWriteArrayList. */ public CopyOnWriteArrayList() { @@ -66,9 +71,9 @@ } /** - * Construct a new ArrayList, and initialize it with the elements in the - * supplied Collection. The initial capacity is 110% of the Collection's size. - * + * Construct a new CopyOnWriteArrayList, and initialize it with the + * elements in the supplied Collection. + * * @param c * the collection whose elements will initialize this list * @throws NullPointerException @@ -84,6 +89,18 @@ } /** + * Construct a new CopyOnWriteArrayList and initialize it with the + * elements of the supplied array. + * + * @param arrayIn the array whose elemts will initialize this list + */ + public CopyOnWriteArrayList(E[] arrayIn) + { +data = (E[]) new Object[arrayIn.length]; +System.arraycopy(arrayIn, 0, data, 0, arrayIn.length); + } + + /** * Returns the number of elements in this list. * * @return the list size
[cp-patches] RFC: [generics] java.util.concurrent.CopyOnWriteArrayList.java small fix
Hi, this fixes a slight oversight in the add methods and implements indexOf(E, int) and lastIndexOf(E, int). Please comment/commit. Thanks, Carsten 2006-07-19 Carsten Neumann <[EMAIL PROTECTED]> * CopyOnWriteArrayList.java (indexOf(E, int)): New method. (lastIndexOf(E, int)): Likewise. (add(E)): Increase the size of newData array by one. (add(int, E)): Likewise. Index: java/util/concurrent/CopyOnWriteArrayList.java === RCS file: /sources/classpath/classpath/java/util/concurrent/Attic/CopyOnWriteArrayList.java,v retrieving revision 1.1.2.1 diff -u -r1.1.2.1 CopyOnWriteArrayList.java --- java/util/concurrent/CopyOnWriteArrayList.java 16 Jun 2006 17:39:13 - 1.1.2.1 +++ java/util/concurrent/CopyOnWriteArrayList.java 19 Jul 2006 20:37:41 - @@ -133,6 +133,25 @@ } /** + * Return the lowest index greater equal index at which + * e appears in this List, or -1 if it does not + * appear. + * + * @param e the element whose inclusion in the list is being tested + * @param index the index at which the search begins + * @return the index where e was found + */ + public int indexOf(E e, int index) + { +E[] data = this.data; + +for (int i = index; i < data.length; i++) + if (equals(e, data[i])) + return i; +return -1; + } + + /** * Returns the highest index at which element appears in this List, or -1 if * it does not appear. * @@ -150,6 +169,25 @@ } /** + * Returns the highest index lesser equal index at + * which e appears in this List, or -1 if it does not + * appear. + * + * @param e the element whose inclusion in the list is being tested + * @param index the index at which the search begins + * @return the index where e was found + */ + public int lastIndexOf(E e, int index) + { +E[] data = this.data; + +for (int i = index; i >= 0; i--) + if (equals(e, data[i])) + return i; +return -1; + } + + /** * Creates a shallow copy of this ArrayList (elements are not cloned). * * @return the cloned object @@ -255,7 +293,7 @@ public synchronized boolean add(E e) { E[] data = this.data; -E[] newData = (E[]) new Object[data.length]; +E[] newData = (E[]) new Object[data.length + 1]; System.arraycopy(data, 0, newData, 0, data.length); newData[data.length] = e; this.data = newData; @@ -277,7 +315,7 @@ public synchronized void add(int index, E e) { E[] data = this.data; -E[] newData = (E[]) new Object[data.length]; +E[] newData = (E[]) new Object[data.length + 1]; System.arraycopy(data, 0, newData, 0, index); newData[index] = e; System.arraycopy(data, index, newData, index + 1, data.length - index);
[cp-patches] RFC: java.awt.color.ICC_Profile missing constants added
Hi, this adds the missing fields pointed out by JAPI (classpath vs. jdk-1.5). Please comment/commit. Thanks, Carsten 2006-07-19 Carsten Neumann <[EMAIL PROTECTED]> * ICC_Profile.java (icHdrProfileID): New field. (icICCAbsoluteColorimetric): Likewise. (icMediaRelativeColorimetric): Likewise. (icSigBlueMatrixColumnTag): Likewise. (icSigChromaticAdaptationTag): Likewise. (icSigColorantOrderTag): Likewise. (icSigColorantTableTag): Likewise. (icSigGreenMatrixColumnTag): Likewise. (icSigRedMatrixColumnTag): Likewise. Index: java/awt/color/ICC_Profile.java === RCS file: /sources/classpath/classpath/java/awt/color/ICC_Profile.java,v retrieving revision 1.13 diff -u -r1.13 ICC_Profile.java --- java/awt/color/ICC_Profile.java 3 Oct 2005 17:21:07 - 1.13 +++ java/awt/color/ICC_Profile.java 19 Jul 2006 17:29:55 - @@ -1,5 +1,5 @@ /* ICC_Profile.java -- color space profiling - Copyright (C) 2000, 2002, 2004 Free Software Foundation + Copyright (C) 2000, 2002, 2004, 2006 Free Software Foundation This file is part of GNU Classpath. @@ -145,8 +145,10 @@ */ public static final int icPerceptual = 0; public static final int icRelativeColorimetric = 1; + public static final int icMediaRelativeColorimetric = 1; public static final int icSaturation = 2; public static final int icAbsoluteColorimetric = 3; + public static final int icICCAbsoluteColorimetric = 3; /** * Tag signatures @@ -154,13 +156,17 @@ public static final int icSigAToB0Tag = 0x41324230; // 'A2B0' public static final int icSigAToB1Tag = 0x41324231; // 'A2B1' public static final int icSigAToB2Tag = 0x41324232; // 'A2B2' - public static final int icSigBlueColorantTag = 0x6258595A; // 'bXYZ' + public static final int icSigBlueColorantTag = 0x6258595A; // 'bXYZ' + public static final int icSigBlueMatrixColumnTag = 0x6258595A; // 'bXYZ' public static final int icSigBlueTRCTag = 0x62545243; // 'bTRC' public static final int icSigBToA0Tag = 0x42324130; // 'B2A0' public static final int icSigBToA1Tag = 0x42324131; // 'B2A1' public static final int icSigBToA2Tag = 0x42324132; // 'B2A2' public static final int icSigCalibrationDateTimeTag = 0x63616C74; // 'calt' - public static final int icSigCharTargetTag = 0x74617267; // 'targ' + public static final int icSigCharTargetTag = 0x74617267; // 'targ' + public static final int icSigChromaticAdaptationTag = 0x63686164; // 'chad' + public static final int icSigColorantOrderTag = 0x636C726F; // 'clro' + public static final int icSigColorantTableTag = 0x636C7274; // 'clrt' public static final int icSigCopyrightTag = 0x63707274; // 'cprt' public static final int icSigCrdInfoTag = 0x63726469; // 'crdi' public static final int icSigDeviceMfgDescTag = 0x646D6E64; // 'dmnd' @@ -169,6 +175,7 @@ public static final int icSigGamutTag = 0x67616D74; // 'gamt' public static final int icSigGrayTRCTag = 0x6b545243; // 'kTRC' public static final int icSigGreenColorantTag = 0x6758595A; // 'gXYZ' + public static final int icSigGreenMatrixColumnTag = 0x6758595A; // 'gXYZ' public static final int icSigGreenTRCTag = 0x67545243; // 'gTRC' public static final int icSigLuminanceTag = 0x6C756d69; // 'lumi' public static final int icSigMeasurementTag = 0x6D656173; // 'meas' @@ -188,6 +195,7 @@ public static final int icSigPs2CSATag = 0x70733273; // 'ps2s' public static final int icSigPs2RenderingIntentTag = 0x70733269; // 'ps2i' public static final int icSigRedColorantTag = 0x7258595A; // 'rXYZ' + public static final int icSigRedMatrixColumnTag = 0x7258595A; // 'rXYZ' public static final int icSigRedTRCTag = 0x72545243; // 'rTRC' public static final int icSigScreeningDescTag = 0x73637264; // 'scrd' public static final int icSigScreeningTag = 0x7363726E; // 'scrn' @@ -214,6 +222,7 @@ public static final int icHdrDate = 24; public static final int icHdrMagic = 36; public static final int icHdrPlatform = 40; + public static final int icHdrProfileId = 84; public static final int icHdrFlags = 44; public static final int icHdrManufacturer = 48; public static final int icHdrModel = 52;
[cp-patches] RFC: StrictMath.java cbrt
Hi, hopefully final version of cbrt. Please comment and/or commit. Thanks, Carsten 2006-07-14 Carsten Neumann <[EMAIL PROTECTED]> * java/lang/StrictMath.java (cbrt): New method. (getLowDWord): New helper method. (getHighDWord): Likewise. (buildDouble): Likewise. (CBRT_B1): New field. (CBRT_B2): Likewise. (CBRT_C): Likewise. (CBRT_D): Likewise. (CBRT_E): Likewise. (CBRT_F): Likewise. (CBRT_G): Likewise. Index: java/lang/StrictMath.java === RCS file: /sources/classpath/classpath/java/lang/StrictMath.java,v retrieving revision 1.8 diff -u -r1.8 StrictMath.java --- java/lang/StrictMath.java 15 Mar 2006 21:57:44 - 1.8 +++ java/lang/StrictMath.java 14 Jul 2006 20:32:13 - @@ -633,6 +633,129 @@ } /** + * Returns the lower two words of a long. This is intended to be + * used like this: + * getLowDWord(Double.doubleToLongBits(x)). + */ + private static int getLowDWord(long x) + { +return (int) (x & 0xL); + } + + /** + * Returns the higher two words of a long. This is intended to be + * used like this: + * getHighDWord(Double.doubleToLongBits(x)). + */ + private static int getHighDWord(long x) + { +return (int) ((x & 0xL) >> 32); + } + + /** + * Returns a double with the IEEE754 bit pattern given in the lower + * and higher two words lowDWord and highDWord. + */ + private static double buildDouble(int lowDWord, int highDWord) + { +return Double.longBitsToDoublelong) highDWord & 0xL) << 32) + | ((long) lowDWord & 0xL)); + } + + /** + * Returns the cube root of x. The sign of the cube root + * is equal to the sign of x. + * + * Special cases: + * + * If the argument is NaN, the result is NaN + * If the argument is positive infinity, the result is positive + * infinity. + * If the argument is negative infinity, the result is negative + * infinity. + * If the argument is zero, the result is zero with the same + * sign as the argument. + * + * + * @param x the number to take the cube root of + * @return the cube root of x + * @see #sqrt(double) + */ + public static double cbrt(double x) + { +boolean negative = (x < 0); +double r; +double s; +double t; +double w; + +long bits; +int l; +int h; + +// handle the special cases +if (x != x) + return Double.NaN; +if (x == Double.POSITIVE_INFINITY) + return Double.POSITIVE_INFINITY; +if (x == Double.NEGATIVE_INFINITY) + return Double.NEGATIVE_INFINITY; +if (x == 0) + return x; + +x = abs(x); +bits = Double.doubleToLongBits(x); + +if (bits < 0x0010L) // subnormal number + { + t = TWO_54; + t *= x; + + // __HI(t)=__HI(t)/3+B2; + bits = Double.doubleToLongBits(t); + h = getHighDWord(bits); + l = getLowDWord(bits); + + h = h / 3 + CBRT_B2; + + t = buildDouble(l, h); + } +else + { + // __HI(t)=__HI(x)/3+B1; + h = getHighDWord(bits); + l = 0; + + h = h / 3 + CBRT_B1; + t = buildDouble(l, h); + } + +// new cbrt to 23 bits +r = t * t / x; +s = CBRT_C + r * t; +t *= CBRT_G + CBRT_F / (s + CBRT_E + CBRT_D / s); + +// chopped to 20 bits and make it larger than cbrt(x) +bits = Double.doubleToLongBits(t); +h = getHighDWord(bits); + +// __LO(t)=0; +// __HI(t)+=0x0001; +l = 0; +h += 1; +t = buildDouble(l, h); + +// one step newton iteration to 53 bits with error less than 0.667 ulps +s = t * t; // t * t is exact +r = x / s; +w = t + t; +r = (r - t) / (w + r); // r - s is exact +t = t + t * r; + +return negative ? -t : t; + } + + /** * Take ea. The opposite of log(). If the * argument is NaN, the result is NaN; if the argument is positive infinity, * the result is positive infinity; and if the argument is negative @@ -1429,6 +1552,23 @@ AT10 = 0.016285820115365782; // Long bits 0x3f90ad3ae322da11L. /** + * Constants for computing [EMAIL PROTECTED] #cbrt(double)}. + */ + private static final int +CBRT_B1 = 715094163, // B1 = (682-0.03306235651)*2**20 +CBRT_B2 = 696219795; // B2 = (664-0.03306235651)*2**20 + + /** + * Constants for computing [EMAIL PROTECTED] #cbrt(double)}. + */ + private static final double +CBRT_C = 5.42857142857142815906e-01, // Long bits 0x3fe15f15f15f15f1L +CBRT_D = -7.05306122448979611050e-01, // Long bits 0xbfe691de2532c834L +CBRT_E = 1.41428571428571436819e+00, // Long bits 0x3ff6a0ea0ea0ea0fL +CBRT_F = 1.60714285714285720630e+00, // Long bits 0x3ff9b6db6db6db6eL +CBRT_G = 3.57142857142857150787e-01; // Long bits 0x3fd6db6db6db6db7L + + /** * Helper function for reducing an angle to a multiple of pi/2 within * [-pi/4, pi/4]. *
[cp-patches] RFC: StrictMath.java - cbrt reworked
Hi, this is reworked version of my previous patches to implement cbrt. I'm somewhat confident that I got it right this time, though ;) A mauve test will follow in a moment. Please comment and/or commit ;) Thanks, Carsten 2006-07-14 Carsten Neumann <[EMAIL PROTECTED]> * java/lang/StrictMath.java (cbrt): New method. (getLowDWord): New helper method. (getHighDWord): Likewise. (buildDouble): Likewise. (CBRT_B1): New field. (CBRT_B2): Likewise. (CBRT_C): Likewise. (CBRT_D): Likewise. (CBRT_E): Likewise. (CBRT_F): Likewise. (CBRT_G): Likewise.
[cp-patches] RFC: StrictMath.java - cbrt reworked
[it looks as if this did not get through to the list yesterday, so i'm resending - and with attachments this time...] Hi, this is reworked version of my previous patches to implement cbrt. I'm somewhat confident that I got it right this time, though ;) A mauve test will follow in a moment. Please comment and/or commit ;) Thanks, Carsten 2006-07-14 Carsten Neumann <[EMAIL PROTECTED]> * java/lang/StrictMath.java (cbrt): New method. (getLowDWord): New helper method. (getHighDWord): Likewise. (buildDouble): Likewise. (CBRT_B1): New field. (CBRT_B2): Likewise. (CBRT_C): Likewise. (CBRT_D): Likewise. (CBRT_E): Likewise. (CBRT_F): Likewise. (CBRT_G): Likewise. 2006-07-14 Carsten Neumann <[EMAIL PROTECTED]> * java/lang/StrictMath.java (cbrt): New method. (getLowDWord): New helper method. (getHighDWord): Likewise. (buildDouble): Likewise. (CBRT_B1): New field. (CBRT_B2): Likewise. (CBRT_C): Likewise. (CBRT_D): Likewise. (CBRT_E): Likewise. (CBRT_F): Likewise. (CBRT_G): Likewise.Index: java/lang/StrictMath.java === RCS file: /sources/classpath/classpath/java/lang/StrictMath.java,v retrieving revision 1.8 diff -u -r1.8 StrictMath.java --- java/lang/StrictMath.java 15 Mar 2006 21:57:44 - 1.8 +++ java/lang/StrictMath.java 14 Jul 2006 20:32:13 - @@ -633,6 +633,129 @@ } /** + * Returns the lower two words of a long. This is intended to be + * used like this: + * getLowDWord(Double.doubleToLongBits(x)). + */ + private static int getLowDWord(long x) + { +return (int) (x & 0xL); + } + + /** + * Returns the higher two words of a long. This is intended to be + * used like this: + * getHighDWord(Double.doubleToLongBits(x)). + */ + private static int getHighDWord(long x) + { +return (int) ((x & 0xL) >> 32); + } + + /** + * Returns a double with the IEEE754 bit pattern given in the lower + * and higher two words lowDWord and highDWord. + */ + private static double buildDouble(int lowDWord, int highDWord) + { +return Double.longBitsToDoublelong) highDWord & 0xL) << 32) + | ((long) lowDWord & 0xL)); + } + + /** + * Returns the cube root of x. The sign of the cube root + * is equal to the sign of x. + * + * Special cases: + * + * If the argument is NaN, the result is NaN + * If the argument is positive infinity, the result is positive + * infinity. + * If the argument is negative infinity, the result is negative + * infinity. + * If the argument is zero, the result is zero with the same + * sign as the argument. + * + * + * @param x the number to take the cube root of + * @return the cube root of x + * @see #sqrt(double) + */ + public static double cbrt(double x) + { +boolean negative = (x < 0); +double r; +double s; +double t; +double w; + +long bits; +int l; +int h; + +// handle the special cases +if (x != x) + return Double.NaN; +if (x == Double.POSITIVE_INFINITY) + return Double.POSITIVE_INFINITY; +if (x == Double.NEGATIVE_INFINITY) + return Double.NEGATIVE_INFINITY; +if (x == 0) + return x; + +x = abs(x); +bits = Double.doubleToLongBits(x); + +if (bits < 0x0010L) // subnormal number + { + t = TWO_54; + t *= x; + + // __HI(t)=__HI(t)/3+B2; + bits = Double.doubleToLongBits(t); + h = getHighDWord(bits); + l = getLowDWord(bits); + + h = h / 3 + CBRT_B2; + + t = buildDouble(l, h); + } +else + { + // __HI(t)=__HI(x)/3+B1; + h = getHighDWord(bits); + l = 0; + + h = h / 3 + CBRT_B1; + t = buildDouble(l, h); + } + +// new cbrt to 23 bits +r = t * t / x; +s = CBRT_C + r * t; +t *= CBRT_G + CBRT_F / (s + CBRT_E + CBRT_D / s); + +// chopped to 20 bits and make it larger than cbrt(x) +bits = Double.doubleToLongBits(t); +h = getHighDWord(bits); + +// __LO(t)=0; +// __HI(t)+=0x0001; +l = 0; +h += 1; +t = buildDouble(l, h); + +// one step newton iteration to 53 bits with error less than 0.667 ulps +s = t * t; // t * t is exact +r = x / s; +w = t + t; +r = (r - t) / (w + r); // r - s is exact +t = t + t * r; + +return negative ? -t : t; + } + + /** * Take ea. The opposite of log(). If the * argument is NaN, the result is NaN; if the argument is positive infinity, * the result is positive infinity; and if the argument is negative @@ -1429,6 +1552,23 @@ AT10 = 0.016285820115365782; // Long bits 0x3f90ad3ae322da11L. /** + * Constants for computing [EMAIL PROTECTED] #cbrt(double)}. + */ + private static final int +
Re: [cp-patches] RFC: java.lang.StrictMath#cbrt "implemented"
Hi Tom, Tom Tromey wrote: >>>>>> "Carsten" == Carsten Neumann <[EMAIL PROTECTED]> writes: > > Carsten> +int[] words = new int[2]; > > I think cbrt should not require allocation. It shouldn't be too hard > to rewrite it without this... could you do that? > Here is an updated version. Cheers, Carsten PS: If accepted, please commit it for me, thanks. 2006-07-13 Carsten Neumann <[EMAIL PROTECTED]> * StrictMath.java (cbrt): New method. (CBRT_B1): New field. (CBRT_B2): Likewise. (CBRT_C): Likewise. (CBRT_D): Likewise. (CBRT_E): Likewise. (CBRT_F): Likewise. (CBRT_G): Likewise. Index: java/lang/StrictMath.java === RCS file: /sources/classpath/classpath/java/lang/StrictMath.java,v retrieving revision 1.8 diff -u -r1.8 StrictMath.java --- java/lang/StrictMath.java 15 Mar 2006 21:57:44 - 1.8 +++ java/lang/StrictMath.java 13 Jul 2006 19:31:28 - @@ -633,6 +633,111 @@ } /** + * Returns the cube root of x. The sign of the cube root + * is equal to the sign of the sign of x. + * Special cases: + * + * If the argument is NaN, the result is NaN + * If the argument is positive infinity, the result is positive + * infinity. + * If the argument is negative infinity, the result is negative + * infinity. + * If the argument is zero, the result is zero with the same + * sign as the argument. + * + * + * @param x the number to take the cube root of + * @return the cube root of x + * @see #sqrt(double) + * @since 1.5 + */ + public static double cbrt(double x) + { +boolean negative = (x < 0); +double r; +double s; +double t = 0.0; +double w; + +long bits; +int lowWord; +int highWord; + +if (negative) + { + x = -x; + } + +// handle the special cases +if (x != x) + { + return Double.NaN; + } +else if (x == Double.POSITIVE_INFINITY) + { + return negative ? Double.NEGATIVE_INFINITY : Double.POSITIVE_INFINITY; + } +else if (x == 0) + { + return negative ? - 0.0 : 0.0; + } + +bits = Double.doubleToLongBits(x); + +if (bits < 0x0010L) // subnormal number + { + t = TWO_54; + t *= x; + + // __HI(t)=__HI(t)/3+B2; + bits = Double.doubleToLongBits(t); + highWord = (int) (bits >> 32); + lowWord = (int) (bits & 0xL); + + highWord = highWord / 3 + CBRT_B2; + bits = ((long) highWord << 32) | ((long) lowWord); + t = Double.longBitsToDouble(bits); + } +else + { + // __HI(t)=__HI(x)/3+B1; + bits = Double.doubleToLongBits(x); + highWord = (int) (bits >> 32); + lowWord = (int) (bits & 0xL); + + highWord = highWord / 3 + CBRT_B1; + bits = ((long) highWord << 32) | ((long) lowWord); + t = Double.longBitsToDouble(bits); + } + +// new cbrt to 23 bits +r = t * t / x; +s = CBRT_C + r * t; +t *= CBRT_G + CBRT_F / (s + CBRT_E + CBRT_D / s); + +// chopped to 20 bits and make it larger than cbrt(x) +bits = Double.doubleToLongBits(x); +highWord = (int) (bits >> 32); + +// __LO(t)=0; +// __HI(t)+=0x0001; +lowWord = 0; +highWord += 1; + +bits = ((long) highWord << 32) | ((long) lowWord); +t = Double.longBitsToDouble(bits); + +// one step newton iteration to 53 bits with error less than 0.667 ulps +s = t * t; // t * t is exact +r = x / s; +w = t + t; +r = (r - t) / (w + r); // r - s is exact +t = t + t * r; + +return negative ? -t : t; + } + + /** * Take ea. The opposite of log(). If the * argument is NaN, the result is NaN; if the argument is positive infinity, * the result is positive infinity; and if the argument is negative @@ -1429,6 +1534,23 @@ AT10 = 0.016285820115365782; // Long bits 0x3f90ad3ae322da11L. /** + * Constants for computing [EMAIL PROTECTED] #cbrt(double)}. + */ + private static final int +CBRT_B1 = 715094163, // B1 = (682-0.03306235651)*2**20 +CBRT_B2 = 696219795; // B2 = (664-0.03306235651)*2**20 + + /** + * Constants for computing [EMAIL PROTECTED] #cbrt(double)}. + */ + private static final double +CBRT_C = 5.42857142857142815906e-01, // Long bits 0x3fe15f15f15f15f1L +CBRT_D = -7.05306122448979611050e-01, // Long bits 0xbfe691de2532c834L +CBRT_E = 1.41428571428571436819e+00, // Long bits 0x3ff6a0ea0ea0ea0fL +CBRT_F = 1.60714285714285720630e+00, // Long bits 0x3ff9b6db6db6db6eL +CBRT_G = 3.57142857142857150787e-01; // Long bits 0x3fd6db6db6db6db7L + + /** * Helper function for reducing an angle to a multiple of pi/2 within * [-pi/4, pi/4]. * 2006-07-13 Carsten Neumann <[EMAIL PROTECTED]> * StrictMath.java (cbrt): New method.
[cp-patches] RFC: java.lang.StrictMath#cbrt "implemented"
Hi, the attached patch implements java.lang.StrictMath#cbrt, but I'm actually quite ashamed to post it: I'm not very knowledgeable about floating point arithmetic, so I just followed the implementation in fdlibm (www.netlib.org/fdlibm). Unfortunately this library does some weird manipulations of the bits of a double, which I simply mimicked in java. Cheers, Carsten 2006-07-13 Carsten Neumann <[EMAIL PROTECTED]> * StrictMath.java (cbrt): New public method. (doubleToLowWord): New helper method. (doubleToHighWord): Likewise. (doubleToWords): Likewise. (wordsToDouble): Likewise. (wordsToDouble): Likewise. Index: java/lang/StrictMath.java === RCS file: /sources/classpath/classpath/java/lang/StrictMath.java,v retrieving revision 1.8 diff -u -r1.8 StrictMath.java --- java/lang/StrictMath.java 15 Mar 2006 21:57:44 - 1.8 +++ java/lang/StrictMath.java 13 Jul 2006 17:29:15 - @@ -633,6 +633,147 @@ } /** + * Helper method to obtain the lower 32 bits of a double in IEEE 754 + * representation. + */ + private static int doubleToLowWord(double x) + { +return (int) (Double.doubleToLongBits(x) & 0xL); + } + + /** + * Helper method to obtain the upper 32 bits of a double in IEEE 754 + * representation. + */ + private static int doubleToHighWord(double x) + { +return (int) ((Double.doubleToLongBits(x) & 0xL ) >> 32); + } + + /** + * Helper method to obtain the upper and lower 32 bits of a double + * in IEEE 754 representation. + */ + private static void doubleToWords(double x, int[] words) + { +long longBits = Double.doubleToLongBits(x); + +words[0] = (int) (longBits & 0xL); +words[1] = (int) ((longBits & 0xL) >> 32); + } + + /** + * Helper method to construct a double from the upper and lower 32 + * bits in words[1] and words[0] resprectively. + */ + private static double wordsToDouble(int[] words) + { +return wordsToDouble(words[0], words[1]); + } + + /** + * Helper method to construct a double from the upper and lower 32 + * bits in highWord and lowWord resprectively. + */ + private static double wordsToDouble(int lowWord, int highWord) + { +return Double.longBitsToDoublelong) highWord) << 32) | ((long) lowWord)); + } + + /** + * Returns the cube root of x. The sign of the cube root + * is equal to the sign of the sign of x. + * Special cases: + * + * If the argument is NaN, the result is NaN + * If the argument is positive infinity, the result is positive + * infinity. + * If the argument is negative infinity, the result is negative + * infinity. + * If the argument is zero, the result is zero with the same + * sign as the argument. + * + * + * @param x the number to take the cube root of + * @return the cube root of x + * @see #sqrt(double) + * @since 1.5 + */ + public static double cbrt(double x) + { +boolean negative = (x < 0); +double r; +double s; +double t = 0.0; +double w; +inthx; +int[] words = new int[2]; + +if (negative) + { + x = -x; + } + +// handle the special cases +if (x != x) + { + return Double.NaN; + } +else if (x == Double.POSITIVE_INFINITY) + { + return negative ? Double.NEGATIVE_INFINITY : Double.POSITIVE_INFINITY; + } +else if (x == 0) + { + return negative ? - 0.0 : 0.0; + } + +hx = doubleToHighWord(x); + +if (hx < 0x0010) // subnormal number + { + t = TWO_54; + t *= x; + + // __HI(t)=__HI(t)/3+B2; + doubleToWords(t, words); + words[1] = words[1] / 3 + CBRT_B2; + t = wordsToDouble(words); + } +else + { + // __HI(t)=hx/3+B1; + doubleToWords(t, words); + words[1] = hx / 3 + CBRT_B1; + t = wordsToDouble(words); + } + +// new cbrt to 23 bits +r = t * t / x; +s = CBRT_C + r * t; +t *= CBRT_G + CBRT_F / (s + CBRT_E + CBRT_D / s); + +// chopped to 20 bits and make it larger than cbrt(x) +doubleToWords(t, words); + +// __LO(t)=0; +// __HI(t)+=0x0001; +words[0] = 0; +words[1] += 1; + +t = wordsToDouble(words); + +// one step newton iteration to 53 bits with error less than 0.667 ulps +s = t * t; // t * t is exact +r = x / s; +w = t + t; +r = (r - t) / (w + r); // r - s is exact +t = t + t * r; + +return negative ? -t : t; + } + + /** * Take ea. The opposite of log(). If the * argument is NaN, the result is NaN; if the argument is positive infinity, * the result is positive infinity; and if the argument is negative @@ -1429,6 +1570,23 @@ AT10 = 0.016285820115365782; // Long bits 0x3f90ad3ae322da11L. /** + * Constants for computing [EMAIL PROTECTED] #cbrt(d
Re: [cp-patches] RFC: javax.swing.text.DefaultCaret
Hi Mark, Mark Wielaard wrote: > Hi Carsten, > > On Sat, 2006-03-25 at 16:48 +0100, Carsten Neumann wrote: >> Mark Wielaard wrote: >>> On Fri, 2006-03-24 at 23:52 +0100, Carsten Neumann wrote: >>> >>>> I've implemented the method: public boolean isActive(). >>> Nice. Useful method also. Last time I worked with the DefaultCaret I was >>> confused there wasn't such a method. I see this was added in 1.5. Could >>> you add a @since 1.5. >> see attached new version of patch. > > I see this was never applied, sorry about that. > Could you take a look at DefaultCaret and see if it is still the correct > way to implement this? Since you submitted the patch Robert added some > new logic and an active field to that class. now it's my turn to apologize for the long delay in answering your request :-/ In answer to your question, I do believe the patch implements what the API doc of the RI specifies, but I'm not sure if that's also what the RI does ;) Anyway, I updated the patch, so it is now against current cvs. I need to finish my diploma thesis (dunno if that's the right translation) at the moment, so I don't have the time to check the RI behaviour, sorry. Cheers, Carsten Index: javax/swing/text/DefaultCaret.java === RCS file: /sources/classpath/classpath/javax/swing/text/DefaultCaret.java,v retrieving revision 1.42 diff -u -r1.42 DefaultCaret.java --- javax/swing/text/DefaultCaret.java 21 Jun 2006 15:35:09 - 1.42 +++ javax/swing/text/DefaultCaret.java 21 Jun 2006 17:56:44 - @@ -1147,6 +1147,24 @@ } /** + * Returns true if this Caret is blinking, + * and false if not. The returned value is independent of + * the visiblity of this Caret as returned by [EMAIL PROTECTED] #isVisible()}. + * + * @return true if this Caret is blinking, + * and false if not. + * @see #isVisible() + * @since 1.5 + */ + public boolean isActive() + { +if (blinkTimer != null) + return blinkTimer.isRunning(); + +return false; + } + + /** * Returns true if this Caret is currently visible, * and false if it is not. *
[cp-patches] RFC: java.io.ObjectStreamConstants documented
Hi, if this is accepted, could someone with CVS write access please commit it, Thanks, Carsten ChangeLog (also attached): 2006-05-25 Carsten Neumann <[EMAIL PROTECTED]> * java/io/ObjectStreamConstants.java: Added API docs. Index: java/io/ObjectStreamConstants.java === RCS file: /sources/classpath/classpath/java/io/ObjectStreamConstants.java,v retrieving revision 1.15 diff -u -r1.15 ObjectStreamConstants.java --- java/io/ObjectStreamConstants.java 21 May 2006 20:53:14 - 1.15 +++ java/io/ObjectStreamConstants.java 25 May 2006 12:41:17 - @@ -50,8 +50,6 @@ */ public interface ObjectStreamConstants { - // FIXME: Javadoc comment these values. - /** * The serialization stream protocol version 1. This version was * the default serialization protocol before JDK 1.2. @@ -70,39 +68,160 @@ */ int PROTOCOL_VERSION_2 = 2; + /** + * The magic number that is written as part of the stream header. + */ short STREAM_MAGIC = (short)0xaced; + + /** + * The stream version number that is written as part of the stream header. + * Note that this is different from the protocol version that specifies + * the data format for the stream. + */ short STREAM_VERSION = 5; + /** + * Token value to designate a null reference in the stream. + */ byte TC_NULL = (byte)112;//0x70 + + /** + * Token value to designate a reference to an already serialized object. + */ byte TC_REFERENCE = (byte)113; //0x71 + + /** + * Token value to designate a class descriptor is next in the stream. + */ byte TC_CLASSDESC = (byte)114; //0x72 + + /** + * Token value to designate a new object is next in the stream. + */ byte TC_OBJECT = (byte)115; //0x73 + + /** + * Token value to designate a new string is next in the stream. + */ byte TC_STRING = (byte)116; //0x74 + + /** + * Token value to designate a new array is next in the stream. + */ byte TC_ARRAY = (byte)117; //0x75 + + /** + * Token reference to designate a reference to a class. + */ byte TC_CLASS = (byte)118; //0x76 + + /** + * Token value to designate a block of primitive data is next in the stream. + * The next byte in the stream holds the size of the block (in bytes). + */ byte TC_BLOCKDATA = (byte)119; //0x77 + + /** + * Token value to designate the end of a block of primitve data. + */ byte TC_ENDBLOCKDATA = (byte)120;//0x78 + + /** + * Token value to designate a reset of the stream state. + */ byte TC_RESET = (byte)121; //0x79 + + /** + * Token value to designate a long block of primitive data is next in the + * stream. The next long in the stream holds the size of the block + * (in bytes). + */ byte TC_BLOCKDATALONG = (byte)122; //0x7A + + /** + * Token value to designate an exception occured during serialization. + */ byte TC_EXCEPTION = (byte)123; //0x7B + + /** + * Token value to designate a long string is next in the stream. + */ byte TC_LONGSTRING = (byte)124; //0x7C + + /** + * Token value to designate a proxy class descriptor is next in the stream. + */ byte TC_PROXYCLASSDESC = (byte)125; //0x7D - byte TC_ENUM = (byte)126;//0x7E + /** + * Token value to designate an enum constant is next in the stream. + * + * @since 1.5 + */ + byte TC_ENUM = (byte)126;//0x7E + + /** + * The first token value. + */ byte TC_BASE = TC_NULL; + + /** + * The last token value. + */ byte TC_MAX = TC_ENUM; + /** + * The first handle that will be assigned to an object, for later references. + */ int baseWireHandle = 0x7e; + /** + * Flag used in ObjectStreamClass to designate that the class + * defines the writeObject method. + */ byte SC_WRITE_METHOD = 0x01; + + /** + * Flag used in ObjectStreamClass to designate that the class + * is serializeable. + */ byte SC_SERIALIZABLE = 0x02; + + /** + * Flag used in ObjectStreamClass to designate that the class + * is externalizable. + */ byte SC_EXTERNALIZABLE = 0x04; + + /** + * Flag used in ObjectStreamClass to designate that + * externalizable data is written in block data mode. + * + * @since 1.2 + */ byte SC_BLOCK_DATA = 0x08; byte SC_ENUM = 0x10; + /** + * Flag used in ObjectStreamClass to designate that the class + * is an enum constant. + * + * @since 1.5 + */ + byte SC_ENUM = 0x10; + + /** + * Constant for use with a SecurityManager to check if + * substitution of objects is allowed. + */ SerializablePermission SUBSTITUTION_PERMISSION = new SerializablePermission("enableSubstitution"); + /** + * Constant for use with a SecurityManager to check if + * overriding of the writeObjec
[cp-patches] RFC: java.sql.* API doc update/extension
Hi, this replaces all my previous patches for java.sql.* and is against CVS head as of 2006-04-21. I do not have CVS write access, so if this is found acceptable, somebody would have to commit it for me. Thanks, Carsten 2006-04-22 Carsten Neumann <[EMAIL PROTECTED]> * javax/sql/Array.java: Fixed eclipse API doc warnings, named method parameters consistendly, documented some methods. * java/sql/Blob.java: Likewise. * java/sql/CallableStatement.java: Likewise. * java/sql/Clob.java: Likewise. * java/sql/Connection.java: Likewise. * java/sql/DatabaseMetaData.java: Likewise. * java/sql/Date.java: Likewise. * java/sql/Driver.java: Likewise. * java/sql/PreparedStatement.java: Likewise. * java/sql/ResultSet.java: Likewise. * java/sql/ResultSetMetaData.java: Likewise. * java/sql/SQLData.java: Likewise. * java/sql/SQLOutput.java: Likewise. * java/sql/SQLWarning.java: Likewise. * java/sql/Statement.java: Likewise. * java/sql/Time.java: Likewise. * java/sql/Timestamp.java: Likewise. java.sql-2006-04-22.diff.gz Description: application/gzip
[PING] Re: [cp-patches] RFC: java.io.ObjectStreamConstants documented
My copyright assignment should be on file now. Wolfgang Baer pointed out that the two fields this patch adds (TC_ENUM, SC_ENUM) are already on the generics branch. Should I split the patch into 2 (one that only documents HEAD and one for the two new fields) to simplify merges ? Thanks, Carsten Carsten Neumann wrote: > > Hi all, > > in addition to the documentation I also added two fields that were added > in 1.5 (TC_ENUM and SC_ENUM). > Please note that my copyright assignment is in snail mail, I'll ping > this message when the paper shuffling is finished. > > Thanks, > Carsten > > The Changelog is: > > 2006-04-07 Carsten Neumann <[EMAIL PROTECTED]> > > * java/io/ObjectStreamConstants.java: Documented fields. > (TC_ENUM): New field. > (SC_ENUM): New field. > (TC_MAX): Changed to reflect addition of TC_ENUM. > > > > > Index: ObjectStreamConstants.java > === > RCS file: /sources/classpath/classpath/java/io/ObjectStreamConstants.java,v > retrieving revision 1.14 > diff -u -r1.14 ObjectStreamConstants.java > --- ObjectStreamConstants.java22 Mar 2006 17:52:33 - 1.14 > +++ ObjectStreamConstants.java6 Apr 2006 21:48:25 - > @@ -50,8 +50,6 @@ > */ > public interface ObjectStreamConstants > { > - // FIXME: Javadoc comment these values. > - >/** > * The serialization stream protocol version 1. This version was > * the default serialization protocol before JDK 1.2. > @@ -70,37 +68,159 @@ > */ >int PROTOCOL_VERSION_2 = 2; > > + /** > + * The magic number that is written as part of the stream header. > + */ >short STREAM_MAGIC = (short)0xaced; > + > + /** > + * The stream version number that is written as part of the stream header. > + * Note that this is different from the protocol version that specifies > + * the data format for the stream. > + */ >short STREAM_VERSION = 5; > > + /** > + * Tag value to designate a null reference in the stream. > + */ >byte TC_NULL = (byte)112;//0x70 > + > + /** > + * Tag value to designate a reference to an already serialized object. > + */ >byte TC_REFERENCE = (byte)113; //0x71 > + > + /** > + * Tag value to designate a class descriptor is next in the stream. > + */ >byte TC_CLASSDESC = (byte)114; //0x72 > + > + /** > + * Tag value to designate a new object is next in the stream. > + */ >byte TC_OBJECT = (byte)115; //0x73 > + > + /** > + * Tag value to designate a new string is next in the stream. > + */ >byte TC_STRING = (byte)116; //0x74 > + > + /** > + * Tag value to designate a new array is next in the stream. > + */ >byte TC_ARRAY = (byte)117; //0x75 > + > + /** > + * Tag reference to designate a reference to a class. > + */ >byte TC_CLASS = (byte)118; //0x76 > + > + /** > + * Tag value to designate a block of primitive data is next in the stream. > + * The next byte in the stream holds the size of the block (in bytes). > + */ >byte TC_BLOCKDATA = (byte)119; //0x77 > + > + /** > + * Tag value to designate the end of a block of primitve data. > + */ >byte TC_ENDBLOCKDATA = (byte)120;//0x78 > + > + /** > + * Tag value to designate a reset of the stream state. > + */ >byte TC_RESET = (byte)121; //0x79 > + > + /** > + * Tag value to designate a long block of primitive data is next in the > + * stream. The next long in the stream holds the size of the block > + * (in bytes). > + */ >byte TC_BLOCKDATALONG = (byte)122; //0x7A > + > + /** > + * Tag value to designate an exception occured during serialization. > + */ >byte TC_EXCEPTION = (byte)123; //0x7B > + > + /** > + * Tag value to designate a long string is next in the stream. > + */ >byte TC_LONGSTRING = (byte)124; //0x7C > + > + /** > + * Tag value to designate a proxy class descriptor is next in the stream. > + */ >byte TC_PROXYCLASSDESC = (byte)125; //0x7D > > + /** > + * Tag value to designate an enum constant is next in the stream. > + * > + * @since 1.5 > + */ > + byte TC_ENUM = (byte)126;//0x7E > + > + /** > + * The first tag value. > + */ >byte TC_BASE = TC_NULL; > - byte TC_MAX = TC_PROXYCLASSDESC; > + > + /** > +
[PING] Re: [cp-patches] RFC: java.sql.* doc comment updates
My copyright assignment should be on file now, please comment and/or commit ;) Thanks, Carsten Carsten Neumann wrote: > > Hi, > > the attached patch removes all warnings I got from eclipse about doc > comment @param tags not matching method signatures and similar. It also > documents some previously undocumented methods. > Please note that my copyright assignment is pending, I'll ping this > message when the paper shuffling is finished. > > Thanks, > Carsten > > ChangeLog (also attached): > > 2006-03-27 Carsten Neumann <[EMAIL PROTECTED]> > > * java/sql/Time.java (Time): Fixed doc comment. > * java/sql/Timestamp.java: Fixed doc comments. > * java/sql/Statement.java: Fixed doc comments. > * java/sql/SQLWarning.java (SQLWarning): Fixed doc comment. > * java/sql/SQLOutput.java: Made the method parameter names more > consistent and adapted doc comments. > (writeURL): Documented. > * java/sql/SQLData.java (readSQL): Fixed doc comment. > * java/sql/Driver.java (connect): Fixed doc comment. > (acceptsURL): Likewise. > * java/sql/DriverManager.java (setLoginTimeout): Fixed doc comment. > (setLogStream): Likewise. > (println): Likewise. > * java/sql/Date.java (Date): Fixed doc comment. > * java/sql/DatabaseMetaData.java: Made the method parameter names more > consistent and adapted doc comments. > (supportsSavepoints): Documented. > (supportsNamedParameters): Likewise. > (supportsMultipleOpenResults): Likewise. > (supportsResultSetHoldability): Likewise. > (getResultSetHoldability): Likewise. > (getDatabaseMajorVersion): Likewise. > (getDatabaseMinorVersion): Likewise. > (getJDBCMajorVersion): Likewise. > (getJDBCMinorVersion): Likewise. > * java/sql/Connection.java: Made the method parameter names more > consistent and adapted doc comments. > (setHoldability): Documented. > (getHoldability): Likewise. > (setSavepoint): Likewise. > (setSavepoint): Likewise. > (rollback): Likewise. > (releaseSavepoint): Likewise. > (createStatement): Likewise. > (prepareStatement): Likewise. > (prepareCall): Likewise. > * java/sql/ResultSet.java: Made the method parameter names more > consistent and adapted doc comments. > (getURL): Documented. > (updateRef): Likewise. > (updateBlob): Likewise. > (updateClob): Likewise. > (updateArray): Likewise. > * java/sql/ResultSetMetaData.java: Made the method parameter names more > consistent and adapted doc comments. > * java/sql/PreparedStatement.java: Made the method parameter names more > consistent and adapted doc comments. > (setURL): Documented. > (getParameterMetaData): Likewise. > * java/sql/Clob.java: Made the method parameter names more > consistent and > adapted doc comments. > (setString): Documented. > (setAsciiStream): Likewise. > (setCharacterStream): Likewise. > (truncate): Likewise. > * java/sql/CallableStatement.java: Made the method parameter names more > consistent and adapted doc comments. > (getURL): Documented. > (setURL): Likewise. > (setNull): Likewise. > (setBoolean): Likewise. > (setByte): Likewise. > (setShort): Likewise. > (setInt): Likewise. > (setLong): Likewise. > (setFloat): Likewise. > (setDouble): Likewise. > (setBigDecimal): Likewise. > (setString): Likewise. > (setBytes): Likewise. > (setDate): Likewise. > (setTime): Likewise. > (setTimestamp): Likewise. > (setAsciiStream): Likewise. > (setBinaryStream): Likewise. > (setObject): Likewise. > (setCharacterStream): Likewise. > (setDate): Likewise. > (setTime): Likewise. > (setTimestamp): Likewise. > (setNull): Likewise. > (getString): Likewise. > (getBoolean): Likewise. > (getByte): Likewise. > (getShort): Likewise. > (getInt): Likewise. > (getLong): Likewise. > (getFloat): Likewise. > (getDouble): Likewise. > (getBytes): Likewise. > (getDate): Likewise. > (getTime): Likewise. > (getTimestamp): Likewise. > (getObject): Likewise. > (getBigDecimal): Likewise. > (getRef): Likewise. > (getBlob): Likewise. > (getClob): Likewise. > (getArray): Likewise. > (getURL): Likewise. > * java/sql/Blob.java: Made the method parameter names more > consistent and > adapted doc comments. > (setBytes): Documented. > (setBinaryStream): Likewise. > (truncate): Likewise. > * java/sql/Arr
[PING] Re: [cp-patches] RFC: javax.swing.text.DefaultCaret
My copyright assignment should be on file now, please comment and/or commit ;) Thanks, Carsten Carsten Neumann wrote: > Hi Mark, > > Mark Wielaard wrote: > >> Hi Casten, >> >> On Fri, 2006-03-24 at 23:52 +0100, Carsten Neumann wrote: >> >>> I've implemented the method: public boolean isActive(). >> >> >> >> Nice. Useful method also. Last time I worked with the DefaultCaret I was >> confused there wasn't such a method. I see this was added in 1.5. Could >> you add a @since 1.5. > > > see attached new version of patch. > >> >>> Please also note that my copyright assignment is pending, but the >>> process has been started. >> >> >> >> Please send a ping (reply to this message on the list) when that is done >> so we don't forget. > > > will do. > >> Just one tiny nitpick. >> >> +if(blinkTimer != null) >> + return blinkTimer.isRunning(); >> >> if normally has a space after it: >> if (blinkTimer != null) >> >> Although I admit that this is not always precisley followed. But please >> see http://www.gnu.org/software/classpath/docs/hacking.html#SEC6 >> Seeing you followed the other guidelines there I assume you have read >> that already :) > > > Oops, that one slipped through, sorry, fixed. > > Thanks, > Carsten > > > > > Index: DefaultCaret.java > === > RCS file: /sources/classpath/classpath/javax/swing/text/DefaultCaret.java,v > retrieving revision 1.36 > diff -u -r1.36 DefaultCaret.java > --- DefaultCaret.java 23 Mar 2006 21:17:22 - 1.36 > +++ DefaultCaret.java 25 Mar 2006 15:46:15 - > @@ -1030,6 +1030,24 @@ >} > >/** > + * Returns true if this Caret is blinking, > + * and false if not. The returned value is independent of > + * the visiblity of this Caret as returned by [EMAIL > PROTECTED] #isVisible()}. > + * > + * @return true if this Caret is blinking, > + * and false if not. > + * @see #isVisible() > + * @since 1.5 > + */ > + public boolean isActive() > + { > +if (blinkTimer != null) > + return blinkTimer.isRunning(); > + > +return false; > + } > + > + /** > * Returns true if this Caret is currently > visible, > * and false if it is not. > *
Re: [cp-patches] Patch: FYI: core bug patrol
Hi Tom, Index: java/io/CharArrayWriter.java === RCS file: /cvsroot/classpath/classpath/java/io/CharArrayWriter.java,v retrieving revision 1.13 diff -u -r1.13 CharArrayWriter.java --- java/io/CharArrayWriter.java27 Mar 2006 21:31:41 - 1.13 +++ java/io/CharArrayWriter.java7 Apr 2006 19:44:27 - @@ -267,7 +267,7 @@ * sequence is wrapped around an input buffer, the results will * depend on the current position and length of that buffer. * - * @param seq the character sequence to append. If seq is null, + * @param cs the character sequence to append. If seq is null, ^^^ this should be changed to cs as well, I think. *then the string "null" (the string representation of null) *is appended. * @return a reference to this object. @@ -294,7 +294,7 @@ * append(seq.subSequence(start,end)) when the sequence * is not null. * - * @param seq the character sequence to append. If seq is null, + * @param cs the character sequence to append. If seq is null, ^^^ same here. *then the string "null" (the string representation of null) *is appended. * @param start the index of the first Unicode character to use from Index: java/lang/Class.java Thanks, Carsten
[cp-patches] RFC: java.io.ObjectStreamConstants documented
Hi all, in addition to the documentation I also added two fields that were added in 1.5 (TC_ENUM and SC_ENUM). Please note that my copyright assignment is in snail mail, I'll ping this message when the paper shuffling is finished. Thanks, Carsten The Changelog is: 2006-04-07 Carsten Neumann <[EMAIL PROTECTED]> * java/io/ObjectStreamConstants.java: Documented fields. (TC_ENUM): New field. (SC_ENUM): New field. (TC_MAX): Changed to reflect addition of TC_ENUM. Index: ObjectStreamConstants.java === RCS file: /sources/classpath/classpath/java/io/ObjectStreamConstants.java,v retrieving revision 1.14 diff -u -r1.14 ObjectStreamConstants.java --- ObjectStreamConstants.java 22 Mar 2006 17:52:33 - 1.14 +++ ObjectStreamConstants.java 6 Apr 2006 21:48:25 - @@ -50,8 +50,6 @@ */ public interface ObjectStreamConstants { - // FIXME: Javadoc comment these values. - /** * The serialization stream protocol version 1. This version was * the default serialization protocol before JDK 1.2. @@ -70,37 +68,159 @@ */ int PROTOCOL_VERSION_2 = 2; + /** + * The magic number that is written as part of the stream header. + */ short STREAM_MAGIC = (short)0xaced; + + /** + * The stream version number that is written as part of the stream header. + * Note that this is different from the protocol version that specifies + * the data format for the stream. + */ short STREAM_VERSION = 5; + /** + * Tag value to designate a null reference in the stream. + */ byte TC_NULL = (byte)112;//0x70 + + /** + * Tag value to designate a reference to an already serialized object. + */ byte TC_REFERENCE = (byte)113; //0x71 + + /** + * Tag value to designate a class descriptor is next in the stream. + */ byte TC_CLASSDESC = (byte)114; //0x72 + + /** + * Tag value to designate a new object is next in the stream. + */ byte TC_OBJECT = (byte)115; //0x73 + + /** + * Tag value to designate a new string is next in the stream. + */ byte TC_STRING = (byte)116; //0x74 + + /** + * Tag value to designate a new array is next in the stream. + */ byte TC_ARRAY = (byte)117; //0x75 + + /** + * Tag reference to designate a reference to a class. + */ byte TC_CLASS = (byte)118; //0x76 + + /** + * Tag value to designate a block of primitive data is next in the stream. + * The next byte in the stream holds the size of the block (in bytes). + */ byte TC_BLOCKDATA = (byte)119; //0x77 + + /** + * Tag value to designate the end of a block of primitve data. + */ byte TC_ENDBLOCKDATA = (byte)120;//0x78 + + /** + * Tag value to designate a reset of the stream state. + */ byte TC_RESET = (byte)121; //0x79 + + /** + * Tag value to designate a long block of primitive data is next in the + * stream. The next long in the stream holds the size of the block + * (in bytes). + */ byte TC_BLOCKDATALONG = (byte)122; //0x7A + + /** + * Tag value to designate an exception occured during serialization. + */ byte TC_EXCEPTION = (byte)123; //0x7B + + /** + * Tag value to designate a long string is next in the stream. + */ byte TC_LONGSTRING = (byte)124; //0x7C + + /** + * Tag value to designate a proxy class descriptor is next in the stream. + */ byte TC_PROXYCLASSDESC = (byte)125; //0x7D + /** + * Tag value to designate an enum constant is next in the stream. + * + * @since 1.5 + */ + byte TC_ENUM = (byte)126;//0x7E + + /** + * The first tag value. + */ byte TC_BASE = TC_NULL; - byte TC_MAX = TC_PROXYCLASSDESC; + + /** + * The last tag value. + */ + byte TC_MAX = TC_ENUM; + /** + * The first handle that will be assigned to an object, for later references. + */ int baseWireHandle = 0x7e; + /** + * Flag used in ObjectStreamClass to designate that the class + * defines the writeObject method. + */ byte SC_WRITE_METHOD = 0x01; + + /** + * Flag used in ObjectStreamClass to designate that the class + * is serializeable. + */ byte SC_SERIALIZABLE = 0x02; + + /** + * Flag used in ObjectStreamClass to designate that the class + * is externalizable. + */ byte SC_EXTERNALIZABLE = 0x04; + + /** + * Flag used in ObjectStreamClass to designate that + * externalizable data is written in block data mode. + * + * @since 1.2 + */ byte SC_BLOCK_DATA = 0x08; + /** + * Flag used in ObjectStreamClass to designate that the class + * is an enum constant. + * + * @since 1.5 + */ + byte SC_ENUM = 0x10; + + /** + * Constant for use with a SecurityManager to check if + * substitution of objects is allowed. + */ SerializablePermission SUBSTITUTION
Re: [cp-patches] FYI:JTable.columnSelectionChanged fix
Hi Audrius, Audrius Meskauskas wrote: 2006-03-31 Audrius Meskauskas <[EMAIL PROTECTED]> * javax/swing/JTable.java (columnSelectionChanged): Treat second repaint parameter as width. Index: JTable.java === RCS file: /sources/classpath/classpath/javax/swing/JTable.java,v retrieving revision 1.92 diff -u -r1.92 JTable.java --- JTable.java 31 Mar 2006 10:13:15 - 1.92 +++ JTable.java 31 Mar 2006 21:05:45 - @@ -1886,6 +1886,7 @@ int idx0 = event.getFirstIndex(); int idxn = event.getLastIndex(); +System.out.println("IDX "+idx0+"-"+idxn); ^^^ looks like this debug code sneaked its way in ;) int i; for (i = 0; i < idx0; i++) @@ -1896,7 +1897,7 @@ for (i = idx0; i <= idxn; i++) xn += columnModel.getColumn(i).getWidth(); -repaint(x0, 0, xn, getHeight()); +repaint(x0, 0, xn-x0, getHeight()); } /** Thanks, Carsten
[cp-patches] RFC: java.sql.* doc comment updates
Hi, the attached patch removes all warnings I got from eclipse about doc comment @param tags not matching method signatures and similar. It also documents some previously undocumented methods. Please note that my copyright assignment is pending, I'll ping this message when the paper shuffling is finished. Thanks, Carsten ChangeLog (also attached): 2006-03-27 Carsten Neumann <[EMAIL PROTECTED]> * java/sql/Time.java (Time): Fixed doc comment. * java/sql/Timestamp.java: Fixed doc comments. * java/sql/Statement.java: Fixed doc comments. * java/sql/SQLWarning.java (SQLWarning): Fixed doc comment. * java/sql/SQLOutput.java: Made the method parameter names more consistent and adapted doc comments. (writeURL): Documented. * java/sql/SQLData.java (readSQL): Fixed doc comment. * java/sql/Driver.java (connect): Fixed doc comment. (acceptsURL): Likewise. * java/sql/DriverManager.java (setLoginTimeout): Fixed doc comment. (setLogStream): Likewise. (println): Likewise. * java/sql/Date.java (Date): Fixed doc comment. * java/sql/DatabaseMetaData.java: Made the method parameter names more consistent and adapted doc comments. (supportsSavepoints): Documented. (supportsNamedParameters): Likewise. (supportsMultipleOpenResults): Likewise. (supportsResultSetHoldability): Likewise. (getResultSetHoldability): Likewise. (getDatabaseMajorVersion): Likewise. (getDatabaseMinorVersion): Likewise. (getJDBCMajorVersion): Likewise. (getJDBCMinorVersion): Likewise. * java/sql/Connection.java: Made the method parameter names more consistent and adapted doc comments. (setHoldability): Documented. (getHoldability): Likewise. (setSavepoint): Likewise. (setSavepoint): Likewise. (rollback): Likewise. (releaseSavepoint): Likewise. (createStatement): Likewise. (prepareStatement): Likewise. (prepareCall): Likewise. * java/sql/ResultSet.java: Made the method parameter names more consistent and adapted doc comments. (getURL): Documented. (updateRef): Likewise. (updateBlob): Likewise. (updateClob): Likewise. (updateArray): Likewise. * java/sql/ResultSetMetaData.java: Made the method parameter names more consistent and adapted doc comments. * java/sql/PreparedStatement.java: Made the method parameter names more consistent and adapted doc comments. (setURL): Documented. (getParameterMetaData): Likewise. * java/sql/Clob.java: Made the method parameter names more consistent and adapted doc comments. (setString): Documented. (setAsciiStream): Likewise. (setCharacterStream): Likewise. (truncate): Likewise. * java/sql/CallableStatement.java: Made the method parameter names more consistent and adapted doc comments. (getURL): Documented. (setURL): Likewise. (setNull): Likewise. (setBoolean): Likewise. (setByte): Likewise. (setShort): Likewise. (setInt): Likewise. (setLong): Likewise. (setFloat): Likewise. (setDouble): Likewise. (setBigDecimal): Likewise. (setString): Likewise. (setBytes): Likewise. (setDate): Likewise. (setTime): Likewise. (setTimestamp): Likewise. (setAsciiStream): Likewise. (setBinaryStream): Likewise. (setObject): Likewise. (setCharacterStream): Likewise. (setDate): Likewise. (setTime): Likewise. (setTimestamp): Likewise. (setNull): Likewise. (getString): Likewise. (getBoolean): Likewise. (getByte): Likewise. (getShort): Likewise. (getInt): Likewise. (getLong): Likewise. (getFloat): Likewise. (getDouble): Likewise. (getBytes): Likewise. (getDate): Likewise. (getTime): Likewise. (getTimestamp): Likewise. (getObject): Likewise. (getBigDecimal): Likewise. (getRef): Likewise. (getBlob): Likewise. (getClob): Likewise. (getArray): Likewise. (getURL): Likewise. * java/sql/Blob.java: Made the method parameter names more consistent and adapted doc comments. (setBytes): Documented. (setBinaryStream): Likewise. (truncate): Likewise. * java/sql/Array.java: Made the method parmater names more consistent and adapted doc comments. java.sql.diff.gz Description: application/gzip 2006-03-27 Carsten Neumann <[EMAIL PROTECTED]> * java/sql/Time.java (Time): Fixed doc comment. * java/sql/Timestamp.java: Fixed doc comments.
Re: [cp-patches] RFC: javax.swing.text.DefaultCaret
Hi Mark, Mark Wielaard wrote: Hi Casten, On Fri, 2006-03-24 at 23:52 +0100, Carsten Neumann wrote: I've implemented the method: public boolean isActive(). Nice. Useful method also. Last time I worked with the DefaultCaret I was confused there wasn't such a method. I see this was added in 1.5. Could you add a @since 1.5. see attached new version of patch. Please also note that my copyright assignment is pending, but the process has been started. Please send a ping (reply to this message on the list) when that is done so we don't forget. will do. Just one tiny nitpick. +if(blinkTimer != null) + return blinkTimer.isRunning(); if normally has a space after it: if (blinkTimer != null) Although I admit that this is not always precisley followed. But please see http://www.gnu.org/software/classpath/docs/hacking.html#SEC6 Seeing you followed the other guidelines there I assume you have read that already :) Oops, that one slipped through, sorry, fixed. Thanks, Carsten Index: DefaultCaret.java === RCS file: /sources/classpath/classpath/javax/swing/text/DefaultCaret.java,v retrieving revision 1.36 diff -u -r1.36 DefaultCaret.java --- DefaultCaret.java 23 Mar 2006 21:17:22 - 1.36 +++ DefaultCaret.java 25 Mar 2006 15:46:15 - @@ -1030,6 +1030,24 @@ } /** + * Returns true if this Caret is blinking, + * and false if not. The returned value is independent of + * the visiblity of this Caret as returned by [EMAIL PROTECTED] #isVisible()}. + * + * @return true if this Caret is blinking, + * and false if not. + * @see #isVisible() + * @since 1.5 + */ + public boolean isActive() + { +if (blinkTimer != null) + return blinkTimer.isRunning(); + +return false; + } + + /** * Returns true if this Caret is currently visible, * and false if it is not. *
[cp-patches] RFC: javax.swing.text.DefaultCaret
Hello, I've implemented the method: public boolean isActive(). Please also note that my copyright assignment is pending, but the process has been started. Thanks, Carsten ChangeLog: 2006-03-24 Carsten Neumann <[EMAIL PROTECTED]> * javax/swing/text/DefaultCaret.java (isActive): New method. Index: DefaultCaret.java === RCS file: /sources/classpath/classpath/javax/swing/text/DefaultCaret.java,v retrieving revision 1.36 diff -u -r1.36 DefaultCaret.java --- DefaultCaret.java 23 Mar 2006 21:17:22 - 1.36 +++ DefaultCaret.java 24 Mar 2006 22:41:44 - @@ -1030,6 +1030,23 @@ } /** + * Returns true if this Caret is blinking, + * and false if not. The returned value is independent of + * the visiblity of this Caret [EMAIL PROTECTED] isVisible}. + * + * @return true if this Caret is blinking, + * and false if not. + * @see #isVisible + */ + public boolean isActive() + { +if(blinkTimer != null) + return blinkTimer.isRunning(); + +return false; + } + + /** * Returns true if this Caret is currently visible, * and false if it is not. *