Exemplo n.º 1
0
 /// <summary>
 /// Try to parse StringEntity to Int64. Cannot accept whitespaces and hex format (this is differ from official C# int.TryParse()).
 /// Use TryParseHex(out T) for hex data.
 /// This function calls the delegate of BurstCompiler.CompileFunctionPointer().
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="source"></param>
 /// <param name="result"></param>
 /// <returns></returns>
 public static bool TryParse <T>(T source, out long result)
     where T : IParseExt
 {
     TryParseBurstCompile._tryParseInt64Delegate((Char16 *)source.GetUnsafePtr(),
                                                 source.Length,
                                                 out bool success, out result);
     return(success);
 }
Exemplo n.º 2
0
 /// <summary>
 /// This function calls the delegate of BurstCompiler.CompileFunctionPointer().
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="source"></param>
 /// <param name="result"></param>
 /// <param name="endian"></param>
 /// <returns></returns>
 public static bool TryParseHex <T>(T source, out double result, Endian endian = Endian.Little)
     where T : IParseExt
 {
     TryParseBurstCompile._tryParseHex64Delegate((Char16 *)source.GetUnsafePtr(),
                                                 source.Length,
                                                 out bool success, out ulong buff, endian);
     if (success)
     {
         result = *(double *)&buff;
     }
     else
     {
         result = 0;
     }
     return(success);
 }
Exemplo n.º 3
0
        /// <summary>
        /// Try to parse StringEntity to float.
        /// Cannot accept whitespaces, comma insertion, and hex format (these are differ from official C# float.TryParse()).
        /// Use TryParseHex(out T) for hex data.
        /// This function calls the delegate of BurstCompiler.CompileFunctionPointer().
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="source"></param>
        /// <param name="result"></param>
        /// <returns></returns>
        public static bool TryParse <T>(T source, out float result)
            where T : IParseExt
        {
            result = 0.0f;

            TryParseBurstCompile._tryParseFloat64Delegate((Char16 *)source.GetUnsafePtr(),
                                                          source.Length,
                                                          out bool success, out double tmp);
            if (!success)
            {
                return(false);
            }

            float f_cast = (float)tmp;

            if (float.IsInfinity(f_cast))
            {
                return(false);
            }

            result = f_cast;
            return(true);
        }