typelevel / algebra
 1 ```package algebra ``` 2 ```package ring ``` 3 4 ```import scala.{ specialized => sp } ``` 5 6 ```trait Field[@sp(Int, Long, Float, Double) A] extends Any with CommutativeRing[A] with MultiplicativeCommutativeGroup[A] { self => ``` 7 8 ``` /** ``` 9 ``` * This is implemented in terms of basic Field ops. However, this is ``` 10 ``` * probably significantly less efficient than can be done with a ``` 11 ``` * specific type. So, it is recommended that this method be ``` 12 ``` * overriden. ``` 13 ``` * ``` 14 ``` * This is possible because a Double is a rational number. ``` 15 ``` */ ``` 16 2 ``` def fromDouble(a: Double): A = Field.defaultFromDouble(a)(self, self) ``` 17 18 ```} ``` 19 20 ```trait FieldFunctions[F[T] <: Field[T]] extends RingFunctions[F] with MultiplicativeGroupFunctions[F] { ``` 21 ``` def fromDouble[@sp(Int, Long, Float, Double) A](n: Double)(implicit ev: F[A]): A = ``` 22 2 ``` ev.fromDouble(n) ``` 23 ```} ``` 24 25 ```object Field extends FieldFunctions[Field] { ``` 26 ``` @inline final def apply[A](implicit ev: Field[A]): Field[A] = ev ``` 27 ```} ```

Read our documentation on viewing source code .