org.apache.spark.SparkException: Task not serializable

Is that the complete code? Cause you seem to have a top-level method (toDoubleOrNeg) and also a main method, which is kind of strange.
Does it make a difference if you try running it without the REPL or spark-shell?