ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/porting.C
(Generate patch)

Comparing deliantra/server/common/porting.C (file contents):
Revision 1.11 by pippijn, Sat Jan 6 14:42:29 2007 UTC vs.
Revision 1.12 by root, Mon Jan 15 01:25:41 2007 UTC

126 } 126 }
127 return (char *) s; 127 return (char *) s;
128} 128}
129 129
130/* 130/*
131 * Based on (n+1)^2 = n^2 + 2n + 1
132 * given that 1^2 = 1, then
133 * 2^2 = 1 + (2 + 1) = 1 + 3 = 4
134 * 3^2 = 4 + (4 + 1) = 4 + 5 = 1 + 3 + 5 = 9
135 * 4^2 = 9 + (6 + 1) = 9 + 7 = 1 + 3 + 5 + 7 = 16
136 * ...
137 * In other words, a square number can be express as the sum of the
138 * series n^2 = 1 + 3 + ... + (2n-1)
139 */
140int
141isqrt (int n)
142{
143 int result, sum, prev;
144
145 result = 0;
146 prev = sum = 1;
147 while (sum <= n)
148 {
149 prev += 2;
150 sum += prev;
151 ++result;
152 }
153 return result;
154}
155
156/*
157 * returns a char-pointer to a static array, in which a representation 131 * returns a char-pointer to a static array, in which a representation
158 * of the decimal number given will be stored. 132 * of the decimal number given will be stored.
159 */ 133 */
160char * 134char *
161ltostr10 (signed long n) 135ltostr10 (signed long n)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines