コード例 #1
0
ファイル: DoubleST.cs プロジェクト: papaathome/CncCalculator
        /// <summary>
        /// Mul operator *: Multiply two values.
        /// </summary>
        /// <param name="left">A value to multiply with</param>
        /// <param name="right">A value to multiply</param>
        /// <returns>(left.value * right.value, [Normalised(left.scale right.scale)])</returns>
        public static DoubleST Mul(DoubleST left, DoubleST right)
        {
            var result = new DoubleST(left.Value * right.Value, left.Scale);

            result.Append(right.Scale);
            return(result);
        }
コード例 #2
0
        /// <summary>
        /// BaseFactor: expressing the ScaleType (1, [target]) in basic Units of the ScaleType
        /// </summary>
        /// <remarks>
        /// Example: ScaleType (1, [cm])
        ///    The BaseUnit for [cm] is Unit.Base, the meter [m]
        ///    BaseNormal = (0.01, [m]), (1, [cm]) = (0.01, [m])
        ///
        /// This value is usefull for checking if a conversion is possible from one value
        /// to another. Both value BaseFactors must have identical scales.
        ///
        /// Pitfall: Do not use for conversion!
        /// e.g.:
        ///    (C1, [m]) = (1, [ft]) = BaseFactor([ft])
        ///    (C2, [m]) = (1, [cm]) = BaseFactor([cm])
        ///    then
        ///    (y, [ft]) = (x, [cm])*(C2, [m])/(C1, [m])
        ///              = (x*C2/C1, [cm])
        ///              The value appears to be correct but the scale is incorrect.
        ///
        /// Note: The relation between
        ///       (c1, [Unit.Base]) = BaseNormal([Unit]) and
        ///       (C1, [Unit]) = BaseFactor([Unit])
        ///       is c1 = 1/C1
        /// </remarks>
        /// <seealso cref="BaseNormal"/>
        /// <param name="target">A list of ScaledUnit instances that form the scale to use.</param>
        /// <returns>
        /// (x, [Unit.Base]), the conversion of (1, [Unit]) where Unit.Base is in { [m], [g], [s],... }
        /// </returns>
        static DoubleST BaseFactor(Scale target)
        {
            var result = new DoubleST(1.0);

            foreach (var s in target)
            {
                result.Append(s.Unit.Base(), s.Exp);
                result = result / s.Factor();
            }
            return(result);
        }
コード例 #3
0
ファイル: DoubleST.cs プロジェクト: papaathome/CncCalculator
        /// <summary>
        /// Div operator /: Divide two values.
        /// </summary>
        /// <param name="left">A value to divide to</param>
        /// <param name="right">A value to divide with</param>
        /// <returns>(left.value / right.value, [Normalised(left.scale, right.scale^-1)])</returns>
        public static DoubleST Div(DoubleST left, DoubleST right)
        {
            if (right.Value == 0.0)
            {
                throw new DivideByZeroException($"{left} / {right} ");
            }
            var result = new DoubleST(left.Value / right.Value, left.Scale);

            result.Append(right.Scale, reciproce: true);
            return(result);
        }