1 // Copyright (c) 1998-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
16 #include <Standard_Stream.hxx>
20 # define finite isfinite
23 // Convert Real to CString in format e with 16 significant digits.
24 // The decimal point character is always a period.
25 // The conversion is independant from current locale database
27 Standard_Boolean OSD::RealToCString(const Standard_Real aReal,
28 Standard_PCharacter& aString)
32 if (Sprintf(aString,"%.17e",aReal) <= 0) //BUC60808
33 return Standard_False ;
35 // Suppress "e+00" and unsignificant 0's
37 p = strchr(aString,'e');
39 if (!strcmp(p,"e+00"))
41 for (q = p-1 ; *q == '0' ; q--) ;
49 return Standard_True ;
52 // Make the RealToCString reciprocal conversion.
54 Standard_Boolean OSD::CStringToReal(const Standard_CString aString,
58 aReal = Strtod(aString, &endptr);
60 return Standard_False ;
64 //=======================================================================
65 //function : OSDSecSleep
66 //purpose : Cause the process to sleep during a amount of seconds
67 //=======================================================================
71 #if !defined(__CYGWIN32__) && !defined(__MINGW32__)
72 //# include <Mapiwin.h>
76 # define DMAXEXP ((1 << _DEXPLEN - 1) - 1 + _IEEE)
77 # define finite _finite
78 # define SLEEP(NSEC) Sleep(1000*(NSEC))
80 # define SLEEP(NSEC) sleep(NSEC)
86 void OSD::SecSleep(const Standard_Integer aDelay)
91 //=======================================================================
92 //function : MilliSecSleep
93 //purpose : Cause the process to sleep during a amount of milliseconds
94 //=======================================================================
98 void OSD::MilliSecSleep(const Standard_Integer aDelay)
105 #include <sys/time.h>
107 void OSD::MilliSecSleep(const Standard_Integer aDelay)
109 struct timeval timeout ;
111 timeout.tv_sec = aDelay / 1000 ;
112 timeout.tv_usec = (aDelay % 1000) * 1000 ;
114 select(0,NULL,NULL,NULL,&timeout) ;
119 //=======================================================================
120 //function : IsDivisible
122 //=======================================================================
124 Standard_Boolean OSD::IsDivisible(const Standard_Real theDividend,const Standard_Real theDivisor)
126 if ( theDivisor == 0. || ! finite(theDividend) ) return Standard_False;
128 // you may divide by infinity
130 if (! finite(theDivisor)) return Standard_True;
132 // Standard_Integer aExp1, aExp2;
133 // Standard_Real aMant1 = frexp(theDividend, &aExp1);
134 // Standard_Real aMant2 = frexp(theDivisor, &aExp2);
136 // Code de :KL:dev:ref :
137 // return ((aExp1-aExp2 < DMAXEXP) || // exponent of the result
138 // (aExp1-aExp2 == DMAXEXP && aMant1 < aMant2)) ;
140 // Code de :KAS:C30 :
141 return Standard_True;
144 // this is unacceptable return for Linux because of (temporary?) undefined aExp1 and aExp2.
145 // Testing both over and underflow should be (:KL:dev ) :
147 // return ((aExp1-aExp2 < DMAXEXP) && (aExp1-aExp2 > DMINEXP) ||
148 // (aExp1-aExp2 == DMAXEXP && aMant1 < aMant2) ||
149 // (aExp1-aExp2 == DMINEXP && aMant1 > aMant2)) ;
152 //=======================================================================
153 //function : GetExponent
155 //=======================================================================
157 //Standard_Integer OSD::GetExponent(const Standard_Real aReal)
158 Standard_Integer OSD::GetExponent(const Standard_Real )
160 // Code de :KAS:C30 :
162 cout << "Function OSD::GetExponent() not yet implemented." << endl;
165 // Code de :KL:dev:ref :
167 // Standard_Integer Exp ;
169 //// Standard_Real Mant = frexp(aReal, &Exp) ;
170 // frexp(aReal, &Exp) ;
174 //=======================================================================
175 //function : GetMantissa
177 //=======================================================================
179 //Standard_Real OSD::GetMantissa(const Standard_Real aReal)
180 Standard_Real OSD::GetMantissa(const Standard_Real )
182 // Code de :KAS:C30 :
183 cout << "Function OSD::GetMantissa() not yet implemented." << endl;
186 // Code de :KL:dev:ref :
188 // Standard_Integer Exp ;
189 // return frexp(aReal, &Exp) ;
192 //=======================================================================
193 // Code de :KAS:C30 :
194 //=======================================================================
195 Standard_Integer OSD::AvailableMemory()
197 cout << "Function OSD::AvailableMemory() not yet implemented." << endl;
201 // Code de :KL:dev:ref ??????????????? :
203 //=======================================================================
204 //function : AvailableMemory
206 //=======================================================================
211 # if defined(SUN) || defined(__sun) || defined(SOLARIS)
212 # define SIZE_MAX 0x7fffffff
213 # elif defined(__osf__) || defined(DECOSF1)
214 # define SIZE_MAX 0x10000000000
216 # define SIZE_MAX 0x7ffdefff
218 # define SIZE_MAX 0xffffffff
221 Standard_Integer OSD::AvailableMemory()
224 size_t max = SIZE_MAX ;
225 size_t middle = SIZE_MAX ;
230 while (min + 1024 < max) {
231 if ((addr = malloc (middle))== (void *)-1) {
232 perror("OSD::AvailableMemory()_malloc error :") ;
243 middle = min + ((max - min ) >> 6) * 63 ;