Skip to content
Browse files

Start adding scala support

* Getting scala to build with scons is kind of annoying
  right now if your run scons twice it will work. Need more pokeing
(going off of https://gist.github.com/1310647 )
  • Loading branch information...
1 parent 0e5af36 commit 5ec3a7439940d3ffe765be96bca79b74774ccf51 @holdenk holdenk committed Apr 10, 2012
Showing with 39 additions and 2 deletions.
  1. +1 −0 SConstruct
  2. +3 −0 scala/MANIFEST
  3. +5 −0 scala/SConscript
  4. +1 −0 scala/SConstruct
  5. +24 −0 scala/src/Erf.scala
  6. +4 −1 scala/{test.scala → src/Main.scala}
  7. +1 −1 test.py
View
1 SConstruct
@@ -6,3 +6,4 @@ SConscript("erlang/SConscript")
SConscript("go/SConscript")
SConscript("java/SConscript")
SConscript("pascal/SConscript")
+SConscript("scala/SConscript")
View
3 scala/MANIFEST
@@ -0,0 +1,3 @@
+Manifest-Version: 1.0
+Created-By: holden@pigscanfly.ca
+Main-Class: Main
View
5 scala/SConscript
@@ -0,0 +1,5 @@
+PACKAGE_NAME = "picomath"
+
+env = Environment(JAVAC = "scalac", JAVASUFFIX=".scala")
+env.Java('classes', 'src')
+env.Jar(PACKAGE_NAME, Glob("classes/*") + ["MANIFEST"])
View
1 scala/SConstruct
@@ -0,0 +1 @@
+SConscript("./SConscript")
View
24 scala/src/Erf.scala
@@ -0,0 +1,24 @@
+import scala.math
+
+class Erf {
+ // constants
+ val a1: Double = 0.254829592;
+ val a2: Double = -0.284496736;
+ val a3: Double = 1.421413741;
+ val a4: Double = -1.453152027;
+ val a5: Double = 1.061405429;
+ val p: Double = 0.3275911;
+
+ def erf(x: Double): Double = {
+ // Save the sign of x
+ val sign = if (x < 0) 1 else 0
+ val absx = math.abs(x)
+
+ // A&S formula 7.1.26
+ val t = 1.0/(1.0 + p*absx);
+ val y = 1.0 - (((((a5*t + a4)*t) + a3)*t + a2)*t + a1)*t*math.exp(-x*x);
+ sign*y
+ }
+}
+
+object Erf extends Erf
View
5 scala/test.scala → scala/src/Main.scala
@@ -9,7 +9,10 @@ object Main extends App {
}
val a: Array[String] = s.split(" ");
val x: Double = a.apply(1).toDouble;
- println("Unknown function: " + a.apply(0));
+ a.apply(0) match {
+ case "erf" => println(Erf.erf(x));
+ case _ => println("Unknown function: " + a.apply(0));
+ }
return;
}
}
View
2 test.py
@@ -19,7 +19,7 @@
"perl": ["perl", "test.pl"],
"python": [sys.executable, "test.py"],
"ruby": ["ruby", "test.rb"],
- "scala": ["scala", "test.scala"],
+ "scala": ["scala", "picomath.jar"],
"scheme": ["guile", "test.scm"],
"tcl": ["tclsh", "test.tcl"],
}

0 comments on commit 5ec3a74

Please sign in to comment.
Something went wrong with that request. Please try again.