… | |
… | |
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 | */ |
|
|
140 | int |
|
|
141 | isqrt (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 | */ |
160 | char * |
134 | char * |
161 | ltostr10 (signed long n) |
135 | ltostr10 (signed long n) |