Why are you thinking in terms of static? All you need to do is create a method with no argument list that returns the Float
forms of your constants.
For better or worse, as you've discovered, imports in a class or trait scope a not inherited.
package rrs.scribble
trait FloatMath
{
import scala.math.{Pi => mPi, cos => mcos, sin => msin}
def Pi: Float = mPi.toFloat
def cos(phi: Float): Float = mcos(phi).toFloat
def sin(phi: Float): Float = msin(phi).toFloat
}
object FM1
extends FloatMath
{
val twoPi = 2.0f * Pi
}
In the REPL:
scala> import rrs.scribble.FM1._
import rrs.scribble.FM1._
scala> twoPi
res0: Float = 6.2831855
scala> cos(twoPi)
res1: Float = 1.0
As you see, the static types of Pi
, twoPi
, cos
, etc. are all Float
, not Double
.