|
6 | 6 | using System;
|
7 | 7 | using System.Collections.Generic;
|
8 | 8 | using System.Linq;
|
9 |
| -using Open.Formatting; |
10 | 9 |
|
11 | 10 | namespace Open.Arithmetic
|
12 | 11 | {
|
@@ -161,7 +160,6 @@ public static double Quotient(this IEnumerable<double> source)
|
161 | 160 | return result;
|
162 | 161 | }
|
163 | 162 |
|
164 |
| - |
165 | 163 | public static double QuotientOf(this IEnumerable<double> divisors, double numerator)
|
166 | 164 | {
|
167 | 165 | var any = false;
|
@@ -198,194 +196,6 @@ public static double Difference(this IEnumerable<double> source)
|
198 | 196 | }
|
199 | 197 |
|
200 | 198 |
|
201 |
| - |
202 |
| - /// <summary> |
203 |
| - /// Ensures addition tolerance by trimming off unexpected imprecision. |
204 |
| - /// </summary> |
205 |
| - public static double SumAccurate(this double source, double value) |
206 |
| - { |
207 |
| - var result = source + value; |
208 |
| - var vp = source.DecimalPlaces(); |
209 |
| - if (vp > 15) |
210 |
| - return result; |
211 |
| - var ap = value.DecimalPlaces(); |
212 |
| - if (ap > 15) |
213 |
| - return result; |
214 |
| - |
215 |
| - var digits = Math.Max(vp, ap); |
216 |
| - |
217 |
| - return Math.Round(result, digits); |
218 |
| - } |
219 |
| - |
220 |
| - /// <summary> |
221 |
| - /// Ensures addition tolerance by trimming off unexpected imprecision. |
222 |
| - /// </summary> |
223 |
| - public static double ProductAccurate(this double source, double value) |
224 |
| - { |
225 |
| - var result = source * value; |
226 |
| - var vp = source.DecimalPlaces(); |
227 |
| - if (vp > 15) |
228 |
| - return result; |
229 |
| - var ap = value.DecimalPlaces(); |
230 |
| - if (ap > 15) |
231 |
| - return result; |
232 |
| - |
233 |
| - var digits = Math.Max(vp, ap); |
234 |
| - |
235 |
| - return Math.Round(result, digits); |
236 |
| - } |
237 |
| - |
238 |
| - /// Ensures addition tolerance by using integer math. |
239 |
| - public static double SumUsingIntegers(this double source, double value) |
240 |
| - { |
241 |
| - var x = Math.Pow(10, Math.Max(source.DecimalPlaces(), value.DecimalPlaces())); |
242 |
| - |
243 |
| - var v = (long)(source * x); |
244 |
| - var a = (long)(value * x); |
245 |
| - var result = v + a; |
246 |
| - return (double)result / x; |
247 |
| - } |
248 |
| - |
249 |
| - |
250 |
| - |
251 |
| - public static bool IsPrime(this int n) |
252 |
| - { |
253 |
| - var a = System.Math.Abs(n); |
254 |
| - if (a == 2 || a == 3) |
255 |
| - return true; |
256 |
| - |
257 |
| - if (a % 2 == 0 || a % 3 == 0) |
258 |
| - return false; |
259 |
| - |
260 |
| - var divisor = 6; |
261 |
| - while (divisor * divisor - 2 * divisor + 1 <= a) |
262 |
| - { |
263 |
| - |
264 |
| - if (a % (divisor - 1) == 0) |
265 |
| - return false; |
266 |
| - |
267 |
| - if (a % (divisor + 1) == 0) |
268 |
| - return false; |
269 |
| - |
270 |
| - divisor += 6; |
271 |
| - |
272 |
| - } |
273 |
| - |
274 |
| - return true; |
275 |
| - |
276 |
| - } |
277 |
| - |
278 |
| - public static bool IsPrime(this double n) |
279 |
| - { |
280 |
| - return (System.Math.Floor(n) == n) |
281 |
| - ? IsPrime((int)n) |
282 |
| - : false; |
283 |
| - } |
284 |
| - |
285 |
| - public static ulong NextPrime(this ulong n) |
286 |
| - { |
287 |
| - if (n == 0) |
288 |
| - return 0; |
289 |
| - |
290 |
| - while (!IsPrime(n)) |
291 |
| - { |
292 |
| - if (n == ulong.MaxValue) |
293 |
| - throw new Exception(string.Format("The next prime is greater than the UInt64.MaxValue of {0}.", ulong.MaxValue)); |
294 |
| - |
295 |
| - n++; |
296 |
| - } |
297 |
| - |
298 |
| - return n; |
299 |
| - } |
300 |
| - |
301 |
| - public static int NextPrime(this int n) |
302 |
| - { |
303 |
| - if (n == 0) |
304 |
| - return 0; |
305 |
| - |
306 |
| - var sign = n < 0 ? -1 : 1; |
307 |
| - n = Math.Abs(n); |
308 |
| - |
309 |
| - while (!IsPrime(++n)) |
310 |
| - { } |
311 |
| - |
312 |
| - return sign * n; |
313 |
| - } |
314 |
| - |
315 |
| - public static int NextPrime(this double a) |
316 |
| - { |
317 |
| - return NextPrime((int)a); |
318 |
| - } |
319 |
| - |
320 |
| - public static IEnumerable<int> Multiples(this int a) |
321 |
| - { |
322 |
| - yield return a < 1 ? -1 : 1; |
323 |
| - if (a < 1) a = Math.Abs(a); |
324 |
| - |
325 |
| - for (var i = 2; a != 1 && i <= a; i = i.NextPrime()) |
326 |
| - { |
327 |
| - while (a % i == 0) |
328 |
| - { |
329 |
| - yield return i; |
330 |
| - a /= i; |
331 |
| - } |
332 |
| - } |
333 |
| - } |
334 |
| - |
335 |
| - |
336 |
| - public static IEnumerable<double> Multiples(this double a) |
337 |
| - { |
338 |
| - if (double.IsNaN(a)) |
339 |
| - { |
340 |
| - yield return a; |
341 |
| - } |
342 |
| - else |
343 |
| - { |
344 |
| - yield return a < 1 ? -1 : 1; |
345 |
| - if (a < 1) a = Math.Abs(a); |
346 |
| - |
347 |
| - if (double.IsInfinity(a) || Math.Floor(a) != a) |
348 |
| - { |
349 |
| - yield return a; |
350 |
| - } |
351 |
| - else |
352 |
| - { |
353 |
| - for (var i = 2; a != 1 && i <= a; i = i.NextPrime()) |
354 |
| - { |
355 |
| - while (a % i == 0) |
356 |
| - { |
357 |
| - yield return i; |
358 |
| - a /= i; |
359 |
| - } |
360 |
| - } |
361 |
| - } |
362 |
| - } |
363 |
| - } |
364 |
| - |
365 |
| - // returns all the primes that do not include 1 or the number itself. |
366 |
| - public static IEnumerable<double> DivisibleMultiples(this double a) |
367 |
| - { |
368 |
| - var m = a.Multiples().Skip(1); |
369 |
| - |
370 |
| - foreach (var i in m) |
371 |
| - { |
372 |
| - if (i == a) break; |
373 |
| - yield return i; |
374 |
| - } |
375 |
| - } |
376 |
| - |
377 |
| - // returns all the primes that do not include 1 or the number itself. |
378 |
| - public static IEnumerable<int> DivisibleMultiples(this int a) |
379 |
| - { |
380 |
| - var m = a.Multiples().Skip(1); |
381 |
| - |
382 |
| - foreach (var i in m) |
383 |
| - { |
384 |
| - if (i == a) break; |
385 |
| - yield return i; |
386 |
| - } |
387 |
| - } |
388 |
| - |
389 | 199 | }
|
390 | 200 | }
|
391 | 201 |
|
|
0 commit comments