public static double convertAlgebra(double value, Algebra src, Algebra dst) {
        if (dst.equals(src)) {
            return value;
        } else if (src.equals(RealAlgebra.getInstance())) {
            return dst.fromReal(value);
        } else if (src.equals(LogSemiring.getInstance())) {
            return dst.fromLogProb(value);
        } else if (dst.equals(RealAlgebra.getInstance())) {
            return src.toReal(value);
        } else if (dst.equals(LogSemiring.getInstance())) {
            return src.toLogProb(value);
        } else {
            // We pivot through the real numbers, but this could cause a loss of
            // floating point precision.
            log.warn("FOR TESTING ONLY: unsafe conversion from " + src + " to " + dst);
            return dst.fromReal(src.toReal(value));
        }
    }
public static double convertAlgebra ( double value , Algebra src , Algebra dst ) { if ( dst . equals ( src ) ) { return value ; } else if ( src . equals ( RealAlgebra . getInstance ( ) ) ) { return dst . fromReal ( value ) ; } else if ( src . equals ( LogSemiring . getInstance ( ) ) ) { return dst . fromLogProb ( value ) ; } else if ( dst . equals ( RealAlgebra . getInstance ( ) ) ) { return src . toReal ( value ) ; } else if ( dst . equals ( LogSemiring . getInstance ( ) ) ) { return src . toLogProb ( value ) ; } else { log . warn ( "FOR TESTING ONLY: unsafe conversion from " + src + " to " + dst ) ; return dst . fromReal ( src . toReal ( value ) ) ; } }
TODO: unit test.