applied patch from Andreas Persenius <ndap@swipnet.se> that updates the
[platform/upstream/glib.git] / gprimes.c
1 /* GLIB - Library of useful routines for C programming
2  * Copyright (C) 1995-1997  Peter Mattis, Spencer Kimball and Josh MacDonald
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 /*
21  * Modified by the GLib Team and others 1997-2000.  See the AUTHORS
22  * file for a list of people on the GLib Team.  See the ChangeLog
23  * files for a list of changes.  These files are distributed with
24  * GLib at ftp://ftp.gtk.org/pub/gtk/. 
25  */
26
27 /* 
28  * MT safe
29  */
30
31 #include "glib.h"
32
33 static const guint g_primes[] =
34 {
35   11,
36   19,
37   37,
38   73,
39   109,
40   163,
41   251,
42   367,
43   557,
44   823,
45   1237,
46   1861,
47   2777,
48   4177,
49   6247,
50   9371,
51   14057,
52   21089,
53   31627,
54   47431,
55   71143,
56   106721,
57   160073,
58   240101,
59   360163,
60   540217,
61   810343,
62   1215497,
63   1823231,
64   2734867,
65   4102283,
66   6153409,
67   9230113,
68   13845163,
69 };
70
71 static const guint g_nprimes = sizeof (g_primes) / sizeof (g_primes[0]);
72
73 guint
74 g_spaced_primes_closest (guint num)
75 {
76   gint i;
77
78   for (i = 0; i < g_nprimes; i++)
79     if (g_primes[i] > num)
80       return g_primes[i];
81
82   return g_primes[g_nprimes - 1];
83 }