I'm trying to scala.math some functions from scala.math to receive and return Float objects, not Double objects, so that I can bind them to a function registrar that works with functions that accept and return Float objects. I tried this rule:
implicit def doubleFunc2floatFunc[T <: { def apply(x:Double):Double }] (func:T) = func(_:Float).floatValue
and it does not work. The compiler complains that my functions are (Double)=>Float , not (Float)=>Float . Can someone point me in the right direction?
EDIT : The code I use in this is as follows:
package org.nathanmoos.magnificalc.exprtreelib.functions import org.nathanmoos.magnificalc.exprtreelib.Functions import scala.math._ object InternalFunctions { implicit def float2double(x:Float) = x.doubleValue // need an implicit def doubleFunc2floatFunc implicit def double2float(x:Double) = x.floatValue def csc(x:Float):Float = 1f/sin(x) def sec(x:Float):Float = 1f/cos(x) def cot(x:Float):Float = 1f/tan(x) def registerAll() = { Functions.register("ln", log _) Functions.register("log", log10 _) Functions.register("sqrt", sqrt _) Functions.register("sin", sin _) Functions.register("cos", cos _) Functions.register("tan", tan _) Functions.register("csc", csc _) Functions.register("sec", sec _) Functions.register("cot", cot _) Functions.register("sinh", sinh _) Functions.register("cosh", cosh _) Functions.register("tanh", tanh _) Functions.register("acos", acos _) Functions.register("asin", asin _) Functions.register("atan", atan _) } }
Functions.register takes a String for the name of the function and the function object to associate it with.
source share