3 #include <Standard_Integer.hxx>
4 #include <Standard_ConstructionError.hxx>
5 #include <Standard_RangeError.hxx>
6 #ifndef _Standard_Stream_HeaderFile
7 #include <Standard_Stream.hxx>
9 #ifndef _Standard_OStream_HeaderFile
10 #include <Standard_OStream.hxx>
13 // ------------------------------------------------------------------
14 // CharToInt : Converts a character in an integer value
15 // ------------------------------------------------------------------
16 const Handle_Standard_Type& Standard_Integer_Type_()
18 static Handle_Standard_Type _aType = new
19 Standard_Type("Standard_Integer",sizeof(Standard_Integer),0,NULL);
24 Standard_Integer CharToInt(const Standard_Character me)
27 Standard_ConstructionError::Raise();
30 Standard_Character S[2];
36 // ------------------------------------------------------------------
37 // CharToInt : Converts a string in an integer value
38 // ------------------------------------------------------------------
40 Standard_Integer CharToInt(const Standard_CString me)
42 const Standard_Size Len = strlen(me);
43 for (Standard_Size I = 0; I < Len; I++)
44 if (!IsDigit(me[I])) {
45 Standard_ConstructionError::Raise();
50 // ------------------------------------------------------------------
51 // ShallowCopy : Copy of an integer
52 // ------------------------------------------------------------------
54 Standard_Integer ShallowCopy (const Standard_Integer me)
57 // ------------------------------------------------------------------
58 // ShallowDump : Writes an integer value
59 // ------------------------------------------------------------------
60 Standard_EXPORT void ShallowDump (const Standard_Integer Value, Standard_OStream& s)
61 { s << Value << " Standard_Integer" << "\n"; }
63 // ------------------------------------------------------------------
64 // NextPrime : Compute the first prime number greater or equal than an integer
65 // ------------------------------------------------------------------
69 long NextPrime (const long me )
72 struct svalue {int signiaib ;
75 struct svalue values[VALUESNBR] ;
80 // int signiaib[4] = { -1 , +1 , +1 , -1 } ;
96 #if defined (__alpha) || defined(DECOSF1)
102 Standard_RangeError::
103 Raise("Try to apply NextPrime method with negative, null or too large value.");
119 minn = ( me - 1 ) / 6 ; // n minimum
120 while ( 6*minn+1 < me ) {
124 maxia = long( sqrt((double ) me ) / 6 + 1 ) ;
126 maxvn = minn + VALUESNBR ;
129 for ( nindd = 0 ; nindd < VALUESNBR ; nindd++ ) {
130 if ( 6*(nindd+minn)-1 < me ) {
131 values[nindd].nbr = 1 ;
132 values[nindd].signiaib = -1 ;
136 values[nindd].nbr = 0 ;
137 values[nindd].signiaib = 0 ;
141 for ( ia = 1 ; ia <= maxia ; ia++ ) {
142 if ( nbvalues == VALUESNBR*2 ) {
145 remain = -VALUESNBR ;
146 ib[0] = ( minn + ia - remain ) / (6*ia - 1) ;
147 n[0] = int ( 6*ia*ib[0] - ia - ib[0] - minn ) ;
148 ib[1] = ( minn - ia - remain ) / (6*ia - 1) ;
149 n[1] = int ( 6*ia*ib[1] + ia - ib[1] - minn ) ;
150 ib[2] = ( minn + ia - remain ) / (6*ia + 1) ;
151 n[2] = int ( 6*ia*ib[2] - ia + ib[2] - minn ) ;
152 ib[3] = ( minn - ia - remain ) / (6*ia + 1) ;
153 n[3] = int ( 6*ia*ib[3] + ia + ib[3] - minn ) ;
154 for ( loop = 0 ; loop < 4 ; loop++ ) {
155 if ( n[loop] >= 0 && n[loop] < VALUESNBR ) {
156 if ( ( values[n[loop]].nbr == 0 ) ||
157 ( values[n[loop]].signiaib == signiaib[loop] ) ) {
158 values[n[loop]].signiaib = -signiaib[loop] ;
159 values[n[loop]].nbr += 1 ;
160 if ( values[n[loop]].nbr <= 2 )
166 for ( nindd = 0 ; nindd < VALUESNBR ; nindd++ ) {
167 if ( values[nindd].nbr == 0 ) {
168 if ( me <= 6*(nindd+minn)-1 ) {
169 premret = 6*(nindd+minn)-1 ;
172 else if ( me <= 6*(nindd+minn)+1 ) {
173 premret = 6*(nindd+minn)+1 ;
177 else if ( values[nindd].nbr == 1 ) {
178 if ( values[nindd].signiaib > 0 ) {
179 if ( me <= 6*(nindd+minn)-1 ) {
180 premret = 6*(nindd+minn)-1 ;
185 if ( me <= 6*(nindd+minn)+1 ) {
186 premret = 6*(nindd+minn)+1 ;
193 if ( premret != 0 ) {
197 return NextPrime ( 6*(maxvn-1)+2) ;
200 static const Standard_Integer Primes[] = {
201 101, 1009, 2003, 3001, 4001, 5003, 6007, 7001, 8009, 9001,
202 10007, 12007, 14009, 16007, 18013,
203 20011, 23003, 26003, 29009,
208 100019}; // catch the biggest
210 const Standard_Integer NbPrimes = 26; // does not include the biggest
212 Standard_Integer NextPrimeForMap(const Standard_Integer N)
215 for (i = 0; i < NbPrimes; i++)
216 if (Primes[i] > N) break;