2
******************************************************************************
4
* Copyright (C) 1997-2001, International Business Machines
5
* Corporation and others. All Rights Reserved.
7
******************************************************************************
11
* Date Name Description
12
* 05/14/98 nos Creation (content moved here from utypes.h).
13
* 06/17/99 erm Added IEEE_754
14
* 07/22/98 stephen Added IEEEremainder, max, min, trunc
15
* 08/13/98 stephen Added isNegativeInfinity, isPositiveInfinity
16
* 08/24/98 stephen Added longBitsFromDouble
17
* 03/02/99 stephen Removed openFile(). Added AS400 support.
18
* 04/15/99 stephen Converted to C
19
* 11/15/99 helena Integrated S/390 changes for IEEE support.
20
* 01/11/00 helena Added u_getVersion.
21
******************************************************************************
27
#include "unicode/utypes.h"
29
/* Define this to 1 if your platform supports IEEE 754 floating point,
30
to 0 if it does not. */
35
/*==========================================================================*/
36
/* Platform utilities */
37
/*==========================================================================*/
40
* Platform utilities isolates the platform dependencies of the
41
* libarary. For each platform which this code is ported to, these
42
* functions may have to be re-implemented.
45
/* Floating point utilities
47
U_CAPI UBool U_EXPORT2 uprv_isNaN(double);
48
U_CAPI UBool U_EXPORT2 uprv_isInfinite(double);
49
U_CAPI UBool U_EXPORT2 uprv_isPositiveInfinity(double);
50
U_CAPI UBool U_EXPORT2 uprv_isNegativeInfinity(double);
51
U_CAPI double U_EXPORT2 uprv_getNaN(void);
52
U_CAPI double U_EXPORT2 uprv_getInfinity(void);
54
U_CAPI double U_EXPORT2 uprv_trunc(double d);
55
U_CAPI double U_EXPORT2 uprv_floor(double x);
56
U_CAPI double U_EXPORT2 uprv_ceil(double x);
57
U_CAPI double U_EXPORT2 uprv_fabs(double x);
58
U_CAPI double U_EXPORT2 uprv_modf(double x, double* y);
59
U_CAPI double U_EXPORT2 uprv_fmod(double x, double y);
60
U_CAPI double U_EXPORT2 uprv_pow(double x, double y);
61
U_CAPI double U_EXPORT2 uprv_pow10(int32_t x);
62
U_CAPI double U_EXPORT2 uprv_fmax(double x, double y);
63
U_CAPI double U_EXPORT2 uprv_fmin(double x, double y);
64
U_CAPI int32_t U_EXPORT2 uprv_max(int32_t x, int32_t y);
65
U_CAPI int32_t U_EXPORT2 uprv_min(int32_t x, int32_t y);
68
# define uprv_isNegative(number) (*((signed char *)&(number))<0)
70
# define uprv_isNegative(number) (*((signed char *)&(number)+sizeof(number)-1)<0)
74
* Return the largest positive number that can be represented by an integer
75
* type of arbitrary bit length.
77
U_CAPI double U_EXPORT2 uprv_maxMantissa(void);
80
* Return the floor of the log base 10 of a given double.
81
* This method compensates for inaccuracies which arise naturally when
82
* computing logs, and always gives the correct value. The parameter
83
* must be positive and finite.
84
* (Thanks to Alan Liu for supplying this function.)
86
* @param d the double value to apply the common log function for.
87
* @return the log of value d.
89
U_CAPI int16_t U_EXPORT2 uprv_log10(double d);
91
U_CAPI double U_EXPORT2 uprv_log(double d);
93
/** Does common notion of rounding e.g. uprv_floor(x + 0.5); */
94
U_CAPI double U_EXPORT2 uprv_round(double x);
97
* Returns the number of digits after the decimal point in a double number x.
99
* @param x the double number
101
U_CAPI int32_t U_EXPORT2 uprv_digitsAfterDecimal(double x);
104
* Time zone utilities
106
* Wrappers for C runtime library functions relating to timezones.
107
* The t_tzset() function (similar to tzset) uses the current setting
108
* of the environment variable TZ to assign values to three global
109
* variables: daylight, timezone, and tzname. These variables have the
110
* following meanings, and are declared in <time.h>.
112
* daylight Nonzero if daylight-saving-time zone (DST) is specified
113
* in TZ; otherwise, 0. Default value is 1.
114
* timezone Difference in seconds between coordinated universal
115
* time and local time. E.g., -28,800 for PST (GMT-8hrs)
116
* tzname(0) Three-letter time-zone name derived from TZ environment
117
* variable. E.g., "PST".
118
* tzname(1) Three-letter DST zone name derived from TZ environment
119
* variable. E.g., "PDT". If DST zone is omitted from TZ,
120
* tzname(1) is an empty string.
122
* Notes: For example, to set the TZ environment variable to correspond
123
* to the current time zone in Germany, you can use one of the
124
* following statements:
129
* If the TZ value is not set, t_tzset() attempts to use the time zone
130
* information specified by the operating system. Under Windows NT
131
* and Windows 95, this information is specified in the Control Panel�s
132
* Date/Time application.
135
U_CAPI void U_EXPORT2 uprv_tzset(void);
138
* Difference in seconds between coordinated universal
139
* time and local time. E.g., -28,800 for PST (GMT-8hrs)
141
U_CAPI int32_t U_EXPORT2 uprv_timezone(void);
144
* tzname(0) Three-letter time-zone name derived from TZ environment
145
* variable. E.g., "PST".
146
* tzname(1) Three-letter DST zone name derived from TZ environment
147
* variable. E.g., "PDT". If DST zone is omitted from TZ,
148
* tzname(1) is an empty string.
150
U_CAPI char* U_EXPORT2 uprv_tzname(int n);
153
* Get UTC (GMT) time measured in seconds since 0:00 on 1/1/70.
156
U_CAPI int32_t U_EXPORT2 uprv_getUTCtime(void);
159
* Return the ICU data directory.
160
* The data directory is where common format ICU data files (.dat files)
161
* are loaded from. Note that normal use of the built-in ICU
162
* facilities does not require loading of an external data file;
163
* unless you are adding custom data to ICU, the data directory
164
* does not need to be set.
166
* The data directory is determined as follows:
167
* If u_setDataDirectory() has been called, that is it, otherwise
168
* if the ICU_DATA environment variable is set, use that, otherwise
169
* On Windows, if the SOFTWARE\ICU\Unicode\Data registry entry exists, use that
170
* (use of the registry in this way is not recommended.) otherwise
171
* If a data directory was specifed at ICU build time, use that
172
* otherwise no data directory is available.
174
* @return the data directory, or an empty string ("") if no data directory has
179
U_CAPI const char* U_EXPORT2 u_getDataDirectory(void);
182
* Set the ICU data directory.
183
* The data directory is where common format ICU data files (.dat files)
184
* are loaded from. Note that normal use of the built-in ICU
185
* facilities does not require loading of an external data file;
186
* unless you are adding custom data to ICU, the data directory
187
* does not need to be set.
189
* This function should be called at most once in a process, before the
190
* first ICU operation that will require the loading of an ICU data file.
194
U_CAPI void U_EXPORT2 u_setDataDirectory(const char *directory);
197
* Return the default codepage for this platform and locale
200
U_CAPI const char* U_EXPORT2 uprv_getDefaultCodepage(void);
203
* Return the default locale ID string by querying ths system, or
204
* zero if one cannot be found.
207
U_CAPI const char* U_EXPORT2 uprv_getDefaultLocaleID(void);
210
* Finds the least double greater than d (if positive == true),
211
* or the greatest double less than d (if positive == false).
213
* This is a special purpose function defined by the ChoiceFormat API
215
* It is not a general purpose function and not defined for NaN or Infinity
216
* @deprecated This will be removed after 2002-Jun-30. Use the ChoiceFormat closures API instead.
218
U_CAPI double U_EXPORT2 uprv_nextDouble(double d, UBool positive);
221
* Filesystem file and path separator characters.
222
* Example: '/' and ':' on Unix, '\\' and ';' on Windows.
226
# define U_FILE_SEP_CHAR ':'
227
# define U_PATH_SEP_CHAR ';'
228
# define U_FILE_SEP_STRING ":"
229
# define U_PATH_SEP_STRING ";"
230
#elif defined(WIN32) || defined(OS2)
231
# define U_FILE_SEP_CHAR '\\'
232
# define U_PATH_SEP_CHAR ';'
233
# define U_FILE_SEP_STRING "\\"
234
# define U_PATH_SEP_STRING ";"
236
# define U_FILE_SEP_CHAR '/'
237
# define U_PATH_SEP_CHAR ':'
238
# define U_FILE_SEP_STRING "/"
239
# define U_PATH_SEP_STRING ":"
243
* Convert char characters to UChar characters.
244
* This utility function is useful only for "invariant characters"
245
* that are encoded in the platform default encoding.
246
* They are a small, constant subset of the encoding and include
247
* just the latin letters, digits, and some punctuation.
248
* For details, see utypes.h .
250
* @param cs Input string, points to <code>length</code>
251
* character bytes from a subset of the platform encoding.
252
* @param us Output string, points to memory for <code>length</code>
253
* Unicode characters.
254
* @param length The number of characters to convert; this may
255
* include the terminating <code>NUL</code>.
258
U_CAPI void U_EXPORT2
259
u_charsToUChars(const char *cs, UChar *us, int32_t length);
262
* Convert UChar characters to char characters.
263
* This utility function is useful only for "invariant characters"
264
* that can be encoded in the platform default encoding.
265
* They are a small, constant subset of the encoding and include
266
* just the latin letters, digits, and some punctuation.
267
* For details, see utypes.h .
269
* @param us Input string, points to <code>length</code>
270
* Unicode characters that can be encoded with the
271
* codepage-invariant subset of the platform encoding.
272
* @param cs Output string, points to memory for <code>length</code>
274
* @param length The number of characters to convert; this may
275
* include the terminating <code>NUL</code>.
278
U_CAPI void U_EXPORT2
279
u_UCharsToChars(const UChar *us, char *cs, int32_t length);
281
/* Define U_UPPER_ORDINAL */
282
#if U_CHARSET_FAMILY==U_ASCII_FAMILY
283
# define U_UPPER_ORDINAL(x) ((x)-'A')
284
#elif U_CHARSET_FAMILY==U_EBCDIC_FAMILY
285
# define U_UPPER_ORDINAL(x) (((x) < 'J') ? ((x)-'A') : \
286
(((x) < 'S') ? ((x)-'J'+9) : \
289
# error Unknown charset family!
293
* Maximum value of a (void*) - use to indicate the limit of an 'infinite' buffer.
294
* In fact, buffer sizes must not exceed 2GB so that the difference between
295
* the buffer limit and the buffer start can be expressed in an int32_t.
297
* The definition of U_MAX_PTR must fulfill the following conditions:
298
* - return the largest possible pointer greater than base
299
* - return a valid pointer according to the machine architecture (AS/400, 64-bit, etc.)
300
* - avoid wrapping around at high addresses
301
* - make sure that the returned pointer is not farther from base than 0x7fffffff
303
* @param base The beginning of a buffer to find the maximum offset from
308
# define U_MAX_PTR(base) ((void *)0x7fffffff)
309
# elif defined(OS400)
311
* With the provided macro we should never be out of range of a given segment
312
* (a traditional/typical segment that is). Our segments have 5 bytes for the id
313
* and 3 bytes for the offset. The key is that the casting takes care of only
314
* retrieving the offset portion minus x1000. Hence, the smallest offset seen in
315
* a program is x001000 and when casted to an int would be 0. That's why we can
316
* only add 0xffefff. Otherwise, we would exceed the segment.
318
* Currently, 16MB is the current addressing limitation on as/400. This macro
319
* may eventually be changed to use 2GB addressability for the newer version of
322
# define U_MAX_PTR(base) ((void *)(((char *)base)-((int32_t)(base))+((int32_t)0xffefff)))
324
# define U_MAX_PTR(base) ((void *)(((char *)(base)+0x7fffffff) > (char *)(base) ? ((char *)(base)+0x7fffffff) : (char *)-1))