u64.cpp

Go to the documentation of this file.
00001 
00032 #include "linden_common.h"
00033 
00034 #include "u64.h"
00035 
00036 
00037 U64 str_to_U64(const char *str)
00038 {
00039         U64 result = 0;
00040         const char *aptr = strpbrk(str,"0123456789");
00041 
00042         if (!aptr)
00043         {
00044                 llwarns << "str_to_U64: Bad string to U64 conversion attempt: format\n" << llendl;
00045         }
00046         else
00047         {
00048                 while ((*aptr >= '0') && (*aptr <= '9'))
00049                 {
00050                         result = result*10 + (*aptr++ - '0');
00051                 }
00052         }
00053         return (result);
00054 }
00055 
00056 
00057 char* U64_to_str(U64 value, char* result, S32 result_size) 
00058 {                                                                               
00059         U32 part1,part2,part3;
00060         
00061         part3 = (U32)(value % (U64)10000000);
00062         
00063         value /= 10000000;
00064         part2 = (U32)(value % (U64)10000000);
00065         
00066         value /= 10000000;
00067         part1 = (U32)(value % (U64)10000000);
00068         
00069         // three cases to avoid leading zeroes unless necessary
00070         
00071         if (part1)
00072         {
00073                 snprintf(       /* Flawfinder: ignore */
00074                         result,
00075                         result_size,
00076                         "%u%07u%07u",
00077                         part1,part2,part3);
00078         }
00079         else if (part2)
00080         {
00081                 snprintf(       /* Flawfinder: ignore */
00082                         result,
00083                         result_size,
00084                         "%u%07u",
00085                         part2,part3);
00086         }
00087         else
00088         {
00089                 snprintf(       /* Flawfinder: ignore */
00090                         result,
00091                         result_size,
00092                         "%u",
00093                         part3);         
00094         }
00095         return (result);
00096 } 
00097 
00098 F64 U64_to_F64(const U64 value)
00099 {
00100         S64 top_bits = (S64)(value >> 1);
00101         F64 result = (F64)top_bits;
00102         result *= 2.f;
00103         result += (U32)(value & 0x01);
00104         return result;
00105 }
00106 
00107 U64     llstrtou64(const char* str, char** end, S32 base)
00108 {
00109 #ifdef LL_WINDOWS
00110         return _strtoui64(str,end,base);
00111 #else
00112         return strtoull(str,end,base);
00113 #endif
00114 }

Generated on Fri May 16 08:32:10 2008 for SecondLife by  doxygen 1.5.5