2 ******************************************************************************
4 * Copyright (C) 1997-2004, International Business Machines
5 * Corporation and others. All Rights Reserved.
7 ******************************************************************************
9 * FILE NAME : putilimp.h
11 * Date Name Description
12 * 10/17/04 grhoten Move internal functions from putil.h to this file.
13 ******************************************************************************
19 #include "unicode/utypes.h"
20 #include "unicode/putil.h"
22 /*==========================================================================*/
23 /* Platform utilities */
24 /*==========================================================================*/
27 * Platform utilities isolates the platform dependencies of the
28 * libarary. For each platform which this code is ported to, these
29 * functions may have to be re-implemented.
33 * Floating point utility to determine if a double is Not a Number (NaN).
36 U_INTERNAL UBool U_EXPORT2
uprv_isNaN(double d
);
38 * Floating point utility to determine if a double has an infinite value.
41 U_INTERNAL UBool U_EXPORT2
uprv_isInfinite(double d
);
43 * Floating point utility to determine if a double has a positive infinite value.
46 U_INTERNAL UBool U_EXPORT2
uprv_isPositiveInfinity(double d
);
48 * Floating point utility to determine if a double has a negative infinite value.
51 U_INTERNAL UBool U_EXPORT2
uprv_isNegativeInfinity(double d
);
53 * Floating point utility that returns a Not a Number (NaN) value.
56 U_INTERNAL
double U_EXPORT2
uprv_getNaN(void);
58 * Floating point utility that returns an infinite value.
61 U_INTERNAL
double U_EXPORT2
uprv_getInfinity(void);
64 * Floating point utility to truncate a double.
67 U_INTERNAL
double U_EXPORT2
uprv_trunc(double d
);
69 * Floating point utility to calculate the floor of a double.
72 U_INTERNAL
double U_EXPORT2
uprv_floor(double d
);
74 * Floating point utility to calculate the ceiling of a double.
77 U_INTERNAL
double U_EXPORT2
uprv_ceil(double d
);
79 * Floating point utility to calculate the absolute value of a double.
82 U_INTERNAL
double U_EXPORT2
uprv_fabs(double d
);
84 * Floating point utility to calculate the fractional and integer parts of a double.
87 U_INTERNAL
double U_EXPORT2
uprv_modf(double d
, double* pinteger
);
89 * Floating point utility to calculate the remainder of a double divided by another double.
92 U_INTERNAL
double U_EXPORT2
uprv_fmod(double d
, double y
);
94 * Floating point utility to calculate d to the power of exponent (d^exponent).
97 U_INTERNAL
double U_EXPORT2
uprv_pow(double d
, double exponent
);
99 * Floating point utility to calculate 10 to the power of exponent (10^exponent).
102 U_INTERNAL
double U_EXPORT2
uprv_pow10(int32_t exponent
);
104 * Floating point utility to calculate the maximum value of two doubles.
107 U_INTERNAL
double U_EXPORT2
uprv_fmax(double d
, double y
);
109 * Floating point utility to calculate the minimum value of two doubles.
112 U_INTERNAL
double U_EXPORT2
uprv_fmin(double d
, double y
);
114 * Private utility to calculate the maximum value of two integers.
117 U_INTERNAL
int32_t U_EXPORT2
uprv_max(int32_t d
, int32_t y
);
119 * Private utility to calculate the minimum value of two integers.
122 U_INTERNAL
int32_t U_EXPORT2
uprv_min(int32_t d
, int32_t y
);
125 # define uprv_isNegative(number) (*((signed char *)&(number))<0)
127 # define uprv_isNegative(number) (*((signed char *)&(number)+sizeof(number)-1)<0)
131 * Return the largest positive number that can be represented by an integer
132 * type of arbitrary bit length.
135 U_INTERNAL
double U_EXPORT2
uprv_maxMantissa(void);
138 * Return the floor of the log base 10 of a given double.
139 * This method compensates for inaccuracies which arise naturally when
140 * computing logs, and always gives the correct value. The parameter
141 * must be positive and finite.
142 * (Thanks to Alan Liu for supplying this function.)
144 * @param d the double value to apply the common log function for.
145 * @return the log of value d.
148 U_INTERNAL
int16_t U_EXPORT2
uprv_log10(double d
);
151 * Floating point utility to calculate the logarithm of a double.
154 U_INTERNAL
double U_EXPORT2
uprv_log(double d
);
157 * Does common notion of rounding e.g. uprv_floor(x + 0.5);
158 * @param x the double number
159 * @return the rounded double
162 U_INTERNAL
double U_EXPORT2
uprv_round(double x
);
166 * Returns the number of digits after the decimal point in a double number x.
168 * @param x the double number
169 * @return the number of digits after the decimal point in a double number x.
172 /*U_INTERNAL int32_t U_EXPORT2 uprv_digitsAfterDecimal(double x);*/
176 * Time zone utilities
178 * Wrappers for C runtime library functions relating to timezones.
179 * The t_tzset() function (similar to tzset) uses the current setting
180 * of the environment variable TZ to assign values to three global
181 * variables: daylight, timezone, and tzname. These variables have the
182 * following meanings, and are declared in <time.h>.
184 * daylight Nonzero if daylight-saving-time zone (DST) is specified
185 * in TZ; otherwise, 0. Default value is 1.
186 * timezone Difference in seconds between coordinated universal
187 * time and local time. E.g., -28,800 for PST (GMT-8hrs)
188 * tzname(0) Three-letter time-zone name derived from TZ environment
189 * variable. E.g., "PST".
190 * tzname(1) Three-letter DST zone name derived from TZ environment
191 * variable. E.g., "PDT". If DST zone is omitted from TZ,
192 * tzname(1) is an empty string.
194 * Notes: For example, to set the TZ environment variable to correspond
195 * to the current time zone in Germany, you can use one of the
196 * following statements:
201 * If the TZ value is not set, t_tzset() attempts to use the time zone
202 * information specified by the operating system. Under Windows NT
203 * and Windows 95, this information is specified in the Control Panel's
204 * Date/Time application.
207 U_INTERNAL
void U_EXPORT2
uprv_tzset(void);
210 * Difference in seconds between coordinated universal
211 * time and local time. E.g., -28,800 for PST (GMT-8hrs)
212 * @return the difference in seconds between coordinated universal time and local time.
215 U_INTERNAL
int32_t U_EXPORT2
uprv_timezone(void);
218 * tzname(0) Three-letter time-zone name derived from TZ environment
219 * variable. E.g., "PST".
220 * tzname(1) Three-letter DST zone name derived from TZ environment
221 * variable. E.g., "PDT". If DST zone is omitted from TZ,
222 * tzname(1) is an empty string.
225 U_INTERNAL
const char* U_EXPORT2
uprv_tzname(int n
);
228 * Get UTC (GMT) time measured in milliseconds since 0:00 on 1/1/1970.
229 * @return the UTC time measured in milliseconds
232 U_INTERNAL UDate U_EXPORT2
uprv_getUTCtime(void);
235 * Determine whether a pathname is absolute or not, as defined by the platform.
236 * @param path Pathname to test
237 * @return TRUE if the path is absolute
238 * @internal (ICU 3.0)
240 U_INTERNAL UBool U_EXPORT2
uprv_pathIsAbsolute(const char *path
);
243 * Maximum value of a (void*) - use to indicate the limit of an 'infinite' buffer.
244 * In fact, buffer sizes must not exceed 2GB so that the difference between
245 * the buffer limit and the buffer start can be expressed in an int32_t.
247 * The definition of U_MAX_PTR must fulfill the following conditions:
248 * - return the largest possible pointer greater than base
249 * - return a valid pointer according to the machine architecture (AS/400, 64-bit, etc.)
250 * - avoid wrapping around at high addresses
251 * - make sure that the returned pointer is not farther from base than 0x7fffffff
253 * @param base The beginning of a buffer to find the maximum offset from
258 # define U_MAX_PTR(base) ((void *)0x7fffffff)
259 # elif defined(OS400)
261 * With the provided macro we should never be out of range of a given segment
262 * (a traditional/typical segment that is). Our segments have 5 bytes for the id
263 * and 3 bytes for the offset. The key is that the casting takes care of only
264 * retrieving the offset portion minus x1000. Hence, the smallest offset seen in
265 * a program is x001000 and when casted to an int would be 0. That's why we can
266 * only add 0xffefff. Otherwise, we would exceed the segment.
268 * Currently, 16MB is the current addressing limitation on as/400. This macro
269 * may eventually be changed to use 2GB addressability for the newer version of
272 # define U_MAX_PTR(base) ((void *)(((char *)base)-((int32_t)(base))+((int32_t)0xffefff)))
274 # define U_MAX_PTR(base) ((void *)(((char *)(base)+0x7fffffffu) > (char *)(base) ? ((char *)(base)+0x7fffffffu) : (char *)-1))