Updates
[glib.git] / glib / gprimes.c
blob7beca710ca13b39511eb756144d29ddc7bf0e1ad
1 /* GLIB - Library of useful routines for C programming
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
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.
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.
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.
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/.
27 /*
28 * MT safe
31 #include "config.h"
33 #include "glib.h"
34 #include "galias.h"
37 static const guint g_primes[] =
39 11,
40 19,
41 37,
42 73,
43 109,
44 163,
45 251,
46 367,
47 557,
48 823,
49 1237,
50 1861,
51 2777,
52 4177,
53 6247,
54 9371,
55 14057,
56 21089,
57 31627,
58 47431,
59 71143,
60 106721,
61 160073,
62 240101,
63 360163,
64 540217,
65 810343,
66 1215497,
67 1823231,
68 2734867,
69 4102283,
70 6153409,
71 9230113,
72 13845163,
75 static const guint g_nprimes = sizeof (g_primes) / sizeof (g_primes[0]);
77 guint
78 g_spaced_primes_closest (guint num)
80 gint i;
82 for (i = 0; i < g_nprimes; i++)
83 if (g_primes[i] > num)
84 return g_primes[i];
86 return g_primes[g_nprimes - 1];
89 #define __G_PRIMES_C__
90 #include "galiasdef.c"