Skip to content
This repository

Delegate to Java's implementation of signum for Long and Int. #23

Merged
merged 1 commit into from over 2 years ago

2 participants

Ismael Juma Paul Phillips
Ismael Juma

The Java implementation is faster as it doesn't have branches.

java.lang.Math includes implementations of signum for Double and Float,
but I didn't change the ones in scala.math because there is a difference
on how negative zero is handled.

Ismael Juma Delegate to Java's implementation of signum for Long and Int.
The Java implementation is faster as it doesn't have branches.

java.lang.Math includes implementations of signum for Double and Float,
but I didn't change the ones in scala.math because there is a difference
on how negative zero is handled.
771f5ca
Paul Phillips paulp merged commit 771f5ca into from December 04, 2011
Paul Phillips paulp closed this December 04, 2011
Ismael Juma

Thanks!

Paul Phillips paulp referenced this pull request from a commit in paulp/scala October 31, 2013
Paul Phillips SI-6546 InnerClasses attribute refers to absent class
At issue is that the optimizer would eliminate closure classes
completely, then neglect to eliminate those classes from the
container's InnerClasses attribute. This breaks tooling which
expects those entries to correspond to real classes.

The code changes are by mgarcia - I only added the test case,
which verifies that after being compiled under -optimise, there
are no inner classes. Before/after:

  7,8d6
  <   InnerClasses:
  <        public final #22; //class A_1$$anonfun$f$1
  37,45c35,40
  <   #21 = Utf8               A_1$$anonfun$f$1
  <   #22 = Class              #21            //  A_1$$anonfun$f$1
  <   #23 = Utf8               Code
  ---
  >   #21 = Utf8               Code
2c6e57f
Paul Phillips paulp referenced this pull request from a commit in paulp/scala November 04, 2013
Paul Phillips SI-6546 InnerClasses attribute refers to absent class
At issue is that the optimizer would eliminate closure classes
completely, then neglect to eliminate those classes from the
container's InnerClasses attribute. This breaks tooling which
expects those entries to correspond to real classes.

The code change is essentially mgarcia's - I minimized it and
put the caches in perRunCaches, and added the test case which
verifies that after being compiled under -optimise, there are
no inner classes. Before/after:

  7,8d6
  <   InnerClasses:
  <        public final #22; //class A_1$$anonfun$f$1
  37,45c35,40
  <   #21 = Utf8               A_1$$anonfun$f$1
  <   #22 = Class              #21            //  A_1$$anonfun$f$1
  <   #23 = Utf8               Code
  ---
  >   #21 = Utf8               Code
075f6f2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Dec 03, 2011
Ismael Juma Delegate to Java's implementation of signum for Long and Int.
The Java implementation is faster as it doesn't have branches.

java.lang.Math includes implementations of signum for Double and Float,
but I didn't change the ones in scala.math because there is a difference
on how negative zero is handled.
771f5ca
This page is out of date. Refresh to see the latest.
12  src/library/scala/math/package.scala
@@ -127,15 +127,9 @@ package object math {
127 127
     else if (x > 0) 1.0f
128 128
     else x    // NaN
129 129
 
130  
-  def signum(x: Long): Long =
131  
-    if (x == 0l) 0l
132  
-    else if (x < 0) -1l
133  
-    else 1l
134  
-
135  
-  def signum(x: Int): Int =
136  
-    if (x == 0) 0
137  
-    else if (x < 0) -1
138  
-    else 1
  130
+  def signum(x: Long): Long = java.lang.Long.signum(x)
  131
+
  132
+  def signum(x: Int): Int = java.lang.Integer.signum(x)
139 133
 
140 134
   // -----------------------------------------------------------------------
141 135
   // root functions
15  test/files/jvm/signum.scala
... ...
@@ -0,0 +1,15 @@
  1
+object Test {
  2
+  def main(args: Array[String]) {
  3
+    assert(math.signum(Long.MaxValue) == 1L)
  4
+    assert(math.signum(1L) == 1L)
  5
+    assert(math.signum(0L) == 0L)
  6
+    assert(math.signum(-1L) == -1L)
  7
+    assert(math.signum(Long.MinValue) == -1L)
  8
+
  9
+    assert(math.signum(Int.MaxValue) == 1)
  10
+    assert(math.signum(1) == 1)
  11
+    assert(math.signum(0) == 0)
  12
+    assert(math.signum(-1) == -1)
  13
+    assert(math.signum(Int.MinValue) == -1)
  14
+  }
  15
+}
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.