/// <summary>
        ///     Determines whether the float literal node is a literal value that overflows/underflows a 32 bit float.
        /// </summary>
        /// <param name="node">The float literal node to test.</param>
        /// <returns><see cref="LSLLiteralOverflowType"/>.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="node"/> is <c>null</c>.</exception>
        public static LSLLiteralOverflowType CheckForOverflow(this ILSLFloatLiteralNode node)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }


            var formatedFloatString = LSLFormatTools.FormatFloatString(node.RawText.TrimEnd('f', 'F'));

            bool nonZero = formatedFloatString.TakeWhile(c => c != 'e').Any(c => c != '0' && c != '.' && c != 'f');

            if (!nonZero)
            {
                return(LSLLiteralOverflowType.None);
            }

            double val;

            try
            {
                val = double.Parse(formatedFloatString);
            }
            catch (OverflowException)
            {
                return(LSLLiteralOverflowType.Overflow);
            }


            if (val > 3.402823466E+38)
            {
                return(LSLLiteralOverflowType.Overflow);
            }
            if (val < 1.401298464E-45)
            {
                return(LSLLiteralOverflowType.Underflow);
            }

            return(LSLLiteralOverflowType.None);
        }
예제 #2
0
 /// <summary>
 ///     Visits a float literal token node during a syntax tree traversal.
 /// </summary>
 /// <param name="node">The Syntax Tree Node.</param>
 /// <returns>An object of type (T) from the visitor implementation of this function.</returns>
 public virtual T VisitFloatLiteral(ILSLFloatLiteralNode node)
 {
     return(default(T));
 }