9
9
package scala
10
10
package math
11
11
12
+ import scala .collection .StringParsers
12
13
import scala .language .implicitConversions
13
14
import scala .util .Try
14
15
@@ -54,7 +55,7 @@ object Numeric {
54
55
def rem (x : Int , y : Int ): Int = x % y
55
56
def negate (x : Int ): Int = - x
56
57
def fromInt (x : Int ): Int = x
57
- def parseString (str : String ): Option [Int ] = Try (str.toInt).toOption
58
+ def parseString (str : String ): Option [Int ] = StringParsers .parseInt (str)
58
59
def toInt (x : Int ): Int = x
59
60
def toLong (x : Int ): Long = x.toLong
60
61
def toFloat (x : Int ): Float = x.toFloat
@@ -70,7 +71,7 @@ object Numeric {
70
71
def rem (x : Short , y : Short ): Short = (x % y).toShort
71
72
def negate (x : Short ): Short = (- x).toShort
72
73
def fromInt (x : Int ): Short = x.toShort
73
- def parseString (str : String ): Option [Short ] = Try (str.toShort).toOption
74
+ def parseString (str : String ): Option [Short ] = StringParsers .parseShort (str)
74
75
def toInt (x : Short ): Int = x.toInt
75
76
def toLong (x : Short ): Long = x.toLong
76
77
def toFloat (x : Short ): Float = x.toFloat
@@ -86,7 +87,7 @@ object Numeric {
86
87
def rem (x : Byte , y : Byte ): Byte = (x % y).toByte
87
88
def negate (x : Byte ): Byte = (- x).toByte
88
89
def fromInt (x : Int ): Byte = x.toByte
89
- def parseString (str : String ): Option [Byte ] = Try (str.toByte).toOption
90
+ def parseString (str : String ): Option [Byte ] = StringParsers .parseByte (str)
90
91
def toInt (x : Byte ): Int = x.toInt
91
92
def toLong (x : Byte ): Long = x.toLong
92
93
def toFloat (x : Byte ): Float = x.toFloat
@@ -118,7 +119,7 @@ object Numeric {
118
119
def rem (x : Long , y : Long ): Long = x % y
119
120
def negate (x : Long ): Long = - x
120
121
def fromInt (x : Int ): Long = x.toLong
121
- def parseString (str : String ): Option [Long ] = Try (str.toLong).toOption
122
+ def parseString (str : String ): Option [Long ] = StringParsers .parseLong (str)
122
123
def toInt (x : Long ): Int = x.toInt
123
124
def toLong (x : Long ): Long = x
124
125
def toFloat (x : Long ): Float = x.toFloat
@@ -132,7 +133,7 @@ object Numeric {
132
133
def times (x : Float , y : Float ): Float = x * y
133
134
def negate (x : Float ): Float = - x
134
135
def fromInt (x : Int ): Float = x.toFloat
135
- def parseString (str : String ): Option [Float ] = Try (str.toFloat).toOption
136
+ def parseString (str : String ): Option [Float ] = StringParsers .parseFloat (str)
136
137
def toInt (x : Float ): Int = x.toInt
137
138
def toLong (x : Float ): Long = x.toLong
138
139
def toFloat (x : Float ): Float = x
@@ -149,7 +150,7 @@ object Numeric {
149
150
def times (x : Double , y : Double ): Double = x * y
150
151
def negate (x : Double ): Double = - x
151
152
def fromInt (x : Int ): Double = x.toDouble
152
- def parseString (str : String ): Option [Double ] = Try (str.toDouble).toOption
153
+ def parseString (str : String ): Option [Double ] = StringParsers .parseDouble (str)
153
154
def toInt (x : Double ): Int = x.toInt
154
155
def toLong (x : Double ): Long = x.toLong
155
156
def toFloat (x : Double ): Float = x.toFloat
0 commit comments