9 #if !defined(HAVE_FINITE) && defined(isfinite)
10 # define finite isfinite
13 static Standard_Integer DecimalPoint = 0 ;
15 static void GetDecimalPoint() {
16 float F1 = (float ) 1.1 ;
19 sprintf(str,"%.1f",F1) ;
20 // printf("%s\n",str) ;
21 DecimalPoint = str[1] ;
24 // Convert Real to CString in format e with 16 significant digits.
25 // The decimal point character is always a period.
26 // The conversion is independant from current locale database
28 Standard_Boolean OSD::RealToCString(const Standard_Real aReal,
29 Standard_PCharacter& aString)
33 // Get the local decimal point character
40 // if (sprintf(aString,"%.15le",aReal) <= 0)
41 if (sprintf(aString,"%.17e",aReal) <= 0) //BUC60808
42 return Standard_False ;
44 if ((p = strchr(aString,DecimalPoint)))
47 // Suppress "e+00" and unsignificant 0's
49 if ((p = strchr(aString,'e'))) {
50 if (!strcmp(p,"e+00"))
52 for (q = p-1 ; *q == '0' ; q--) ;
60 return Standard_True ;
63 // Make the RealToCString reciprocal conversion.
65 Standard_Boolean OSD::CStringToReal(const Standard_CString aString,
72 // Get the local decimal point character
77 const char *str = aString;
79 //if((p = strchr(aString,'.')))
80 if(DecimalPoint != '.' && (p = strchr(aString,'.'))&& ((p-aString) < 1000) )
82 strncpy(buff, aString, 1000);
83 buff[p-aString] = DecimalPoint ;
86 aReal = strtod(str,&endptr) ;
88 return Standard_False ;
92 //=======================================================================
93 //function : OSDSecSleep
94 //purpose : Cause the process to sleep during a amount of seconds
95 //=======================================================================
99 #if !defined(__CYGWIN32__) && !defined(__MINGW32__)
100 # include <Mapiwin.h>
104 # define DMAXEXP ((1 << _DEXPLEN - 1) - 1 + _IEEE)
105 # define finite _finite
106 # define SLEEP(NSEC) Sleep(1000*(NSEC))
108 # define SLEEP(NSEC) sleep(NSEC)
112 //# include <values.h>
119 void OSD::SecSleep(const Standard_Integer aDelay)
124 //=======================================================================
125 //function : MilliSecSleep
126 //purpose : Cause the process to sleep during a amount of milliseconds
127 //=======================================================================
131 void OSD::MilliSecSleep(const Standard_Integer aDelay)
138 #ifdef HAVE_SYS_TIME_H
139 # include <sys/time.h>
142 void OSD::MilliSecSleep(const Standard_Integer aDelay)
145 struct timeval timeout ;
147 timeout.tv_sec = aDelay / 1000 ;
148 timeout.tv_usec = (aDelay % 1000) * 1000 ;
150 fdn = select(0,NULL,NULL,NULL,&timeout) ;
155 //=======================================================================
156 //function : IsDivisible
158 //=======================================================================
160 Standard_Boolean OSD::IsDivisible(const Standard_Real theDividend,const Standard_Real theDivisor)
162 if ( theDivisor == 0. || ! finite(theDividend) ) return Standard_False;
164 // you may divide by infinity
166 if (! finite(theDivisor)) return Standard_True;
168 // Standard_Integer aExp1, aExp2;
169 // Standard_Real aMant1 = frexp(theDividend, &aExp1);
170 // Standard_Real aMant2 = frexp(theDivisor, &aExp2);
172 // Code de :KL:dev:ref :
173 // return ((aExp1-aExp2 < DMAXEXP) || // exponent of the result
174 // (aExp1-aExp2 == DMAXEXP && aMant1 < aMant2)) ;
176 // Code de :KAS:C30 :
177 return Standard_True;
180 // this is unacceptable return for Linux because of (temporary?) undefined aExp1 and aExp2.
181 // Testing both over and underflow should be (:KL:dev ) :
183 // return ((aExp1-aExp2 < DMAXEXP) && (aExp1-aExp2 > DMINEXP) ||
184 // (aExp1-aExp2 == DMAXEXP && aMant1 < aMant2) ||
185 // (aExp1-aExp2 == DMINEXP && aMant1 > aMant2)) ;
188 //=======================================================================
189 //function : GetExponent
191 //=======================================================================
193 //Standard_Integer OSD::GetExponent(const Standard_Real aReal)
194 Standard_Integer OSD::GetExponent(const Standard_Real )
196 // Code de :KAS:C30 :
198 cout << "Function OSD::GetExponent() not yet implemented." << endl;
201 // Code de :KL:dev:ref :
203 // Standard_Integer Exp ;
205 //// Standard_Real Mant = frexp(aReal, &Exp) ;
206 // frexp(aReal, &Exp) ;
210 //=======================================================================
211 //function : GetMantissa
213 //=======================================================================
215 //Standard_Real OSD::GetMantissa(const Standard_Real aReal)
216 Standard_Real OSD::GetMantissa(const Standard_Real )
218 // Code de :KAS:C30 :
219 cout << "Function OSD::GetMantissa() not yet implemented." << endl;
222 // Code de :KL:dev:ref :
224 // Standard_Integer Exp ;
225 // return frexp(aReal, &Exp) ;
228 //=======================================================================
229 // Code de :KAS:C30 :
230 //=======================================================================
231 Standard_Integer OSD::AvailableMemory()
233 cout << "Function OSD::AvailableMemory() not yet implemented." << endl;
237 // Code de :KL:dev:ref ??????????????? :
239 //=======================================================================
240 //function : AvailableMemory
242 //=======================================================================
247 # if defined(SUN) || defined(__sun) || defined(SOLARIS)
248 # define SIZE_MAX 0x7fffffff
249 # elif defined(__osf__) || defined(DECOSF1)
250 # define SIZE_MAX 0x10000000000
252 # define SIZE_MAX 0x7ffdefff
254 # define SIZE_MAX 0xffffffff
257 Standard_Integer OSD::AvailableMemory()
260 size_t max = SIZE_MAX ;
261 size_t middle = SIZE_MAX ;
266 while (min + 1024 < max) {
267 if ((addr = malloc (middle))== (void *)-1) {
268 perror("OSD::AvailableMemory()_malloc error :") ;
279 middle = min + ((max - min ) >> 6) * 63 ;