History log of /libcore/luni/src/main/java/java/lang/Math.java
Revision Date Author Comments
bf9c47975631cda6ead2eda00d3db3c93444eeba 14-Sep-2012 Elliott Hughes <enh@google.com> Manually inline StrictMath.min(JJ) and StrictMath.max(JJ).

Also add new intrinsic tests.

Bug: 7146208
Change-Id: Ic454c8c5b218c51ce1c21f0c11163455392b4e72
08343a4ef77616fc420e51d1095c0d6a266041ba 16-Feb-2011 Elliott Hughes <enh@google.com> Remove our implementations of inline natives.

It turns out that our String.equals was getting used. Making dalvikvm's inline
natives be native methods ensures that doesn't happen.

I've also added a test to ensure we explicitly test both variants.

Change-Id: Ie2a4b5289092da5ffca4a4273692f1048ab3b841
750d24b13461035a89c9af8ec7555588da1cc3d0 27-Jan-2011 Elliott Hughes <enh@google.com> Better tests for Float.parseFloat/Double.parseDouble, plus some fixes.

I'm not happy with the magic 1024s, and I had hoped to have one hack to
cover both harmony bugs. But this passes all our existing tests, all
harmony's existing tests, and the new tests I wrote while looking at
the code. (The new tests all pass on the RI too.)

I've also made a few doc comments slightly less unclear.

Change-Id: Ib72fd20bb3b157c7db5a09913247eed3cc746a2e
2fc5dcd5614f910f25d794d272834752a72e63b1 09-Dec-2010 Elliott Hughes <enh@google.com> Apply various Intellij quick fixes to java.lang.

There's one real bug here: our Integer.toString was supposed to have a cache
for small negative values, but an accidentally-introduced temporary meant we
were never using the cached values. Other than that, this is just cleanup.

Change-Id: I457f9bd166c9a029ba8b439f3bbfa926f9b84cc9
706de1164836051ab31cc69eb77a6bba1a723896 27-Aug-2010 Elliott Hughes <enh@google.com> Minor tidy-up of Float.toString and Double.toString.

This patch looks larger than it is. I've moved duplicated constants out of
Math and StrictMath and into Float and Double where they belong. I've also
moved a table out of BigDecimal so I can reuse it in NumberConverter, which
I've renamed to RealToString.

The main active ingredient here is that there's no longer StringBuilder usage
to prepend '-'. This actually brings us down from 74ns to 62ns for an easy
case like 123.45f.

[cherry-pick of 910106e29fe98f14b2c36312a7498287273ba826 from dalvik-dev to gingerbread; plus build fix]

Bug: 2934304
Change-Id: Id79a6fb0d739e673b7428d240fc48bdae9b8bb43
d16c314465f7f5905fe8852eaa09d4e7e14ec835 25-Aug-2010 Elliott Hughes <enh@google.com> Faster implementations of Math/StrictMath's copySign methods.

These are only faster than the old native implementations now we have
intrinsics for float/int and double/long conversion, but given those,
they're about 4x faster.

We were already using Java for getExponent, the other obvious candidate
for an all-Java implementation.

[cherry-pick of a61c63c54ba46bb8a1dcbd888e3b29d6cedfb1ff from dalvik-dev to gingerbread]

Bug: 2935622
910106e29fe98f14b2c36312a7498287273ba826 27-Aug-2010 Elliott Hughes <enh@google.com> Minor tidy-up of Float.toString and Double.toString.

This patch looks larger than it is. I've moved duplicated constants out of
Math and StrictMath and into Float and Double where they belong. I've also
moved a table out of BigDecimal so I can reuse it in NumberConverter, which
I've renamed to RealToString.

The main active ingredient here is that there's no longer StringBuilder usage
to prepend '-'. This actually brings us down from 74ns to 62ns for an easy
case like 123.45f.

Bug: 2934304
Change-Id: I65461753247eeb9ff890ffe66b0bc79d66d2ec9c
a61c63c54ba46bb8a1dcbd888e3b29d6cedfb1ff 25-Aug-2010 Elliott Hughes <enh@google.com> Faster implementations of Math/StrictMath's copySign methods.

These are only faster than the old native implementations now we have
intrinsics for float/int and double/long conversion, but given those,
they're about 4x faster.

We were already using Java for getExponent, the other obvious candidate
for an all-Java implementation.

Bug: 2935622
Change-Id: I77549c88b7448b6087a67b37f8c317579b4f92b8
e22935d3c7040c22b48d53bd18878844f381287c 13-Aug-2010 Elliott Hughes <enh@google.com> Remove most of our C-style casts.

After being burned by an incorrect C-style cast that cast away const, I've been
keen to remove them all and turn on -Wold-style-cast. This patch doesn't get us
that far, but it does kill the majority of our C-style casts. In turn, the
majority of the casts that it removes are the ones from our tables of native
methods to be registered.

The new NATIVE_METHOD macro also _enforces_ our convention of using the
"Class_nativeMethod" style of naming. Mostly this works out fine. In some
cases (most notably ExpatParser and ExpatAttributes) I've had to un-overload
a few functions, but I don't like overloading anyway, and in the particular
case of a native method, where the stack trace doesn't show a line number,
overloading makes it one step harder to work out which native method you're
actually in. So good riddance to that. The only unfortunate case is
Math.copySign, where there are two overloads corresponding to copysign(3)
and copysignf(3). I had to add an extra layer of indirection there. In my
defense, we've never shipped these functions before, they're unlikely to
become anyone's hotspot, and the right fix is to be doing such trivial work
on the Java side anyway, with intrinsics making the conversion between
float/double and int/long cheap.

This patch also replaces other C-style casts, primarily in
"OSNetworkSystem.cpp".

This patch also removes unnecessary uses of the "struct" keyword.

This patch also fixes a "may be used uninitialized" warning (now error) in
the sim build for "ICU.cpp".

The remaining C-style casts are in the hairy float-parsing code. That stuff --
and turning on -Wold-style-cast -- will have to wait for another day.

Change-Id: I9b3ee14aefd4676f980f6a7ca757595d78d80e6a
5d40b59c6bba79dc978f173ad64cdfbd8a937018 08-Jul-2010 Elliott Hughes <enh@google.com> Clean up File.createTempFile and make Math.random thread-safe.

File.createTempFile has long annoyed me: using a SecureRandom but then always
incrementing by one is silly. Using a new Random is more random, more scalable,
and slightly faster than reusing a SecureRandom according to my benchmark.

Relatedly, access to the Random used by Math.random wasn't synchronized, which
is a bug.

I've also fixed a typo in a comment in a test. Woo!

Change-Id: Ief72ec0e378ed3d5807c278c589f7b0e44c21d3e
1d7a5c66d9973f3383e7e4f9f8be5262161a1421 23-Jun-2010 Elliott Hughes <enh@google.com> Fix Math.atan2 documentation.

The StrictMath.atan2 documentation is already correct.

Bug: http://code.google.com/p/android/issues/detail?id=9260
Change-Id: Ibd86cf7fe73a120578840dce4126a902a827fb40
162a12c1442641a95fe95859fa4e561b22db049f 25-May-2010 Elliott Hughes <enh@google.com> Remove @hide from Java 6 API.

I've left the two new spi packages @hidden, because I think we shouldn't
support them without convincing demand from developers (and I don't
believe there could be such a thing --- they just don't make sense, and
if we add anything, it should be the ability to provide extra ICU data).

Also fix a handful of javadoc syntax errors in Arrays.java and TreeMap.java.

Bug: 2497395
Change-Id: I4176b72daff0face4ed6c7ee1d1f4267d52006b4
f33eae7e84eb6d3b0f4e86b59605bb3de73009f3 13-May-2010 Elliott Hughes <enh@google.com> Remove all trailing whitespace from the dalvik team-maintained parts of libcore.

Gentlemen, you may now set your editors to "strip trailing whitespace"...

Change-Id: I85b2f6c80e5fbef1af6cab11789790b078c11b1b
eeefcae2980c8db05ec08303b5b112afce232d26 06-May-2010 Elliott Hughes <enh@google.com> Remove the "Answers" javadoc barbarism.

I didn't realize how little of it was left, or I'd have done this earlier.

Change-Id: Ic4c23c3779bbee0ed4a8117584c5332e04536b5d
ace7e6ff6285c073a80aaad68321b17bdcd09a4b 27-Mar-2010 Elliott Hughes <enh@google.com> Fix StrictMath.copySign's behavior with NaN.

StrictMath's copySign method is defined to treat all NaNs as positive, regardless
of their sign bit. Rather than add yet more code on the Java side (which already
called down to native code three times), let's just make one call to native code.

This change fixes failures in already-committed StrictMath tests.

The only other potential instances of this class of error were in the
max and min methods, but they all handle NaNs before calling
(double|float)To(Raw)?LongBits, so the choice there really is arbitrary.

Change-Id: I439dbdff9068cb420b78a6330cde9d7d0d12c0ef
5820c2d5ea8199005b9c1c9dbf34b3d5cdbb8c10 11-Mar-2010 Elliott Hughes <enh@google.com> Tidy up java.lang.Math and java.lang.StrictMath.

Removes duplication, fixes typos, and removes some unnecessary object creation.
Note that otherwise-duplicated code that calls a native method needs to remain
duplicated, because the native methods have different implementations. Other
than that, it's not clear to me that the remaining textual differences (mainly
scalb and its implementation details) are meaningful, but it's not clear that
they're not, so I'm leaving them for now. We can always come back later.

This new code still passes all the junit and jtreg tests.

Change-Id: Ica28a01fd1469a162e05deccdb9e6f919246d9f3
73342e0a7adba5a494309c1fcee0c64fee4f79f1 11-Mar-2010 Elliott Hughes <enh@google.com> Copy harmony's jdk6 Math and StrictMath.

There's some ugliness here I want to remove, but it'll be less confusing if
I commit the upstream code first without my changes...

...that said, I've reverted the upstream Math.pow change because it it's just
cruft; we already pass their tests and jtreg's more thorough pow tests (see
http://blogs.sun.com/darcy/entry/finding_a_bug_in_fdlibm). My guess is that
their real problem was that they were using the buggy fdlibm 5.2 until after
they made the Math.pow change. We've always used 5.3, so we were fine.

Change-Id: I5a6c080d9fd6b60dc7bf77ac10096a913766f512
4fefecee9d4a5d2a4510f516b4015607b19e8d09 13-Nov-2009 Jean-Baptiste Queru <jbq@google.com> eclair snapshot
5839b909d9528b7726e678a4b696ed37df15d897 10-Oct-2009 Jesse Wilson <jessewilson@google.com> Udating luni to Harmony r823222.

Highlights:
- InputStream.skip concurrency issue
- "better" messages in bound exceptions for streams and arrays
- prefer fewer writes to underlying streams (using byte[] buffers)
- Rename subclasses to not reuse names from their superclasses
- PlatformAddressFactory.allocMap bugfix

Plus some spelling fixes, style fixes, serial version UIDs and other
boilerplate improvements.
a389b4a499f40379b0b204d7ba1c2057663d95c0 11-Aug-2009 Jesse Wilson <jessewilson@google.com> Update Luni to Harmony r802921.

Notable changes:
- replaced StringBuffer with StringBuilder in several places
- fixed a problem with BufferedInputStream's newline characters (EBCDIC)
- cleanup Timer's finalizer helper object
- new cache for the canonical path of a file
- fixed concurrency issue with ArrayList
- floating point parsing now trims length for very small numbers
- encoding specified "UTF-8" when converting some byte[]s to strings (JarURLConnection, Util, OSFileSystem)
- Harmony now implements floor and ceil in Java. We continue to use native code.
f5597e626ecf7949d249dea08c1a2964d890ec11 25-Jul-2009 Jesse Wilson <jessewilson@google.com> Integrate luni module (but not tests) to Harmony r772995.

Notable changes
- Stripped "@since Android 1.0" from many files. Most files
are now 100% the same in Dalvik and Harmony.
- AbstractStringBuilder.reverse() supports surrogates
- AbstractStringBuilder shares less to waste less memory
- Bitset optimized
- BufferedInputStream changed to support unsynchronized close()
- BufferedOutputStream does flushInternal
- BufferedReader supports EBCDIC NEL
- Collections.synchronizedList().indexOf() does a copy for more concurrency
- Classes in nio module changed: DatagramChannelImpl, SocketChannelImpl
and ServerSocketChannelImpl (these depend on internal APIs changed in
this update)
- DataInputStream/DataOutputStream now use a small buffer to limit the
number of times the underlying stream is accessed
- Date now has a minutes offset, more efficient toString()
- ExposedByteArrayInputStream: new internal class
- DeleteOnExit moved to top-level class
- FileDescriptor.isValid() now non-native
- Float, Double lessThan optimized (fix for compare(-0.0F, 0.0F) still pending)
- FileURLConnection now guesses content types from streams
- HashMap iterator changes
- Hashtable iterator changes
- INetworkSystem
- removes bind2(), createMulticastSocket, sendStream(),
- renames createSocket to createStreamSocket
- JarURLConnection rewritten
- LinkedHashMap: new iterator
- Locale, Currency, TimeZone: now use ICU in Harmony, plain Java in Dalvik
- ObjectInputStream: Accessor objects in Harmony, direct native in Dalvik
- ProxyClassFile - many changes
- String - optimized ascii for toLowerCase, toUpperCase, compare
- Timer - rewritten
- TreeMap - rewritten
- URLClassLoader - new
- URLConnection - new guessContentTypeFromStream(), uses org.apache.harmony.awt.www.content
to lookup content type handlers
adc854b798c1cfe3bfd4c27d68d5cee38ca617da 04-Mar-2009 The Android Open Source Project <initial-contribution@android.com> auto import from //depot/cupcake/@135843
1c0fed63c71ddb230f3b304aac12caffbedf2f21 04-Mar-2009 The Android Open Source Project <initial-contribution@android.com> auto import from //depot/cupcake/@135843
dd828f42a5c83b4270d4fbf6fce2da1878f1e84a 18-Dec-2008 The Android Open Source Project <initial-contribution@android.com> Code drop from //branches/cupcake/...@124589
fdb2704414a9ed92394ada0d1395e4db86889465 21-Oct-2008 The Android Open Source Project <initial-contribution@android.com> Initial Contribution