diff options
author | Jacek Antonelli | 2008-08-15 23:44:46 -0500 |
---|---|---|
committer | Jacek Antonelli | 2008-08-15 23:44:46 -0500 |
commit | 38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4 (patch) | |
tree | adca584755d22ca041a2dbfc35d4eca01f70b32c /linden/indra/llcommon/u64.cpp | |
parent | README.txt (diff) | |
download | meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.zip meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.gz meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.bz2 meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.xz |
Second Life viewer sources 1.13.2.12
Diffstat (limited to 'linden/indra/llcommon/u64.cpp')
-rw-r--r-- | linden/indra/llcommon/u64.cpp | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/linden/indra/llcommon/u64.cpp b/linden/indra/llcommon/u64.cpp new file mode 100644 index 0000000..45baa13 --- /dev/null +++ b/linden/indra/llcommon/u64.cpp | |||
@@ -0,0 +1,110 @@ | |||
1 | /** | ||
2 | * @file u64.cpp | ||
3 | * @brief Utilities to deal with U64s. | ||
4 | * | ||
5 | * Copyright (c) 2001-2007, Linden Research, Inc. | ||
6 | * | ||
7 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
8 | * to you under the terms of the GNU General Public License, version 2.0 | ||
9 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
10 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
11 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
12 | * online at http://secondlife.com/developers/opensource/gplv2 | ||
13 | * | ||
14 | * There are special exceptions to the terms and conditions of the GPL as | ||
15 | * it is applied to this Source Code. View the full text of the exception | ||
16 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
17 | * online at http://secondlife.com/developers/opensource/flossexception | ||
18 | * | ||
19 | * By copying, modifying or distributing this software, you acknowledge | ||
20 | * that you have read and understood your obligations described above, | ||
21 | * and agree to abide by those obligations. | ||
22 | * | ||
23 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
24 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
25 | * COMPLETENESS OR PERFORMANCE. | ||
26 | */ | ||
27 | |||
28 | #include "linden_common.h" | ||
29 | |||
30 | #include "u64.h" | ||
31 | |||
32 | |||
33 | U64 str_to_U64(const char *str) | ||
34 | { | ||
35 | U64 result = 0; | ||
36 | char *aptr = strpbrk(str,"0123456789"); | ||
37 | |||
38 | if (!aptr) | ||
39 | { | ||
40 | llwarns << "str_to_U64: Bad string to U64 conversion attempt: format\n" << llendl; | ||
41 | } | ||
42 | else | ||
43 | { | ||
44 | while ((*aptr >= '0') && (*aptr <= '9')) | ||
45 | { | ||
46 | result = result*10 + (*aptr++ - '0'); | ||
47 | } | ||
48 | } | ||
49 | return (result); | ||
50 | } | ||
51 | |||
52 | |||
53 | char* U64_to_str(U64 value, char* result, S32 result_size) | ||
54 | { | ||
55 | U32 part1,part2,part3; | ||
56 | |||
57 | part3 = (U32)(value % (U64)10000000); | ||
58 | |||
59 | value /= 10000000; | ||
60 | part2 = (U32)(value % (U64)10000000); | ||
61 | |||
62 | value /= 10000000; | ||
63 | part1 = (U32)(value % (U64)10000000); | ||
64 | |||
65 | // three cases to avoid leading zeroes unless necessary | ||
66 | |||
67 | if (part1) | ||
68 | { | ||
69 | snprintf( | ||
70 | result, | ||
71 | result_size, | ||
72 | "%u%07u%07u", | ||
73 | part1,part2,part3); /* Flawfinder: ignore */ | ||
74 | } | ||
75 | else if (part2) | ||
76 | { | ||
77 | snprintf( | ||
78 | result, | ||
79 | result_size, | ||
80 | "%u%07u", | ||
81 | part2,part3); /* Flawfinder: ignore */ | ||
82 | } | ||
83 | else | ||
84 | { | ||
85 | snprintf( | ||
86 | result, | ||
87 | result_size, | ||
88 | "%u", | ||
89 | part3); /* Flawfinder: ignore */ | ||
90 | } | ||
91 | return (result); | ||
92 | } | ||
93 | |||
94 | F64 U64_to_F64(const U64 value) | ||
95 | { | ||
96 | S64 top_bits = (S64)(value >> 1); | ||
97 | F64 result = (F64)top_bits; | ||
98 | result *= 2.f; | ||
99 | result += (U32)(value & 0x01); | ||
100 | return result; | ||
101 | } | ||
102 | |||
103 | U64 llstrtou64(const char* str, char** end, S32 base) | ||
104 | { | ||
105 | #ifdef LL_WINDOWS | ||
106 | return _strtoui64(str,end,base); | ||
107 | #else | ||
108 | return strtoull(str,end,base); | ||
109 | #endif | ||
110 | } | ||