/// <summary> /// If the current calculator for the <typeparamref name="T"/> type does not support conversions /// from the double type AND the <paramref name="num"/> does not exceed the range of long, /// this method will result in smaller number of exceptions, because /// if <paramref name="num"/> value contains only integral part, the 'fromInt(int)' calculator method /// will be preferred over the 'fromDouble(double)'. /// </summary> /// <typeparam name="T">The type of numbers for the calculator.</typeparam> /// <param name="calculator">The calling calculator object.</param> /// <param name="num">The number which is to be converted to the <typeparamref name="T"/> type.</param> /// <returns>The <typeparamref name="T"/> value returned by either fromInt (preferred) of fromDouble calculator method.</returns> public static T fromDoubleSafe <T>(this ICalc <T> calculator, double num) { if (Numeric <double, CalcDouble> .Calculator.fracPart(num) == 0 && num > long.MinValue && num < long.MaxValue) { return(calculator.fromInt((long)num)); } return(calculator.fromDouble(num)); }