sl@0: /* sl@0: ****************************************************************************** sl@0: * sl@0: * Copyright (C) 1997-2005, International Business Machines sl@0: * Corporation and others. All Rights Reserved. sl@0: * sl@0: ****************************************************************************** sl@0: * sl@0: * FILE NAME : putilimp.h sl@0: * sl@0: * Date Name Description sl@0: * 10/17/04 grhoten Move internal functions from putil.h to this file. sl@0: ****************************************************************************** sl@0: */ sl@0: sl@0: #ifndef PUTILIMP_H sl@0: #define PUTILIMP_H sl@0: sl@0: #include "unicode/utypes.h" sl@0: #include "unicode/putil.h" sl@0: sl@0: /*==========================================================================*/ sl@0: /* Platform utilities */ sl@0: /*==========================================================================*/ sl@0: sl@0: /** sl@0: * Platform utilities isolates the platform dependencies of the sl@0: * libarary. For each platform which this code is ported to, these sl@0: * functions may have to be re-implemented. sl@0: */ sl@0: sl@0: /** sl@0: * Floating point utility to determine if a double is Not a Number (NaN). sl@0: * @internal sl@0: */ sl@0: U_INTERNAL UBool U_EXPORT2 uprv_isNaN(double d); sl@0: /** sl@0: * Floating point utility to determine if a double has an infinite value. sl@0: * @internal sl@0: */ sl@0: U_INTERNAL UBool U_EXPORT2 uprv_isInfinite(double d); sl@0: /** sl@0: * Floating point utility to determine if a double has a positive infinite value. sl@0: * @internal sl@0: */ sl@0: U_INTERNAL UBool U_EXPORT2 uprv_isPositiveInfinity(double d); sl@0: /** sl@0: * Floating point utility to determine if a double has a negative infinite value. sl@0: * @internal sl@0: */ sl@0: U_INTERNAL UBool U_EXPORT2 uprv_isNegativeInfinity(double d); sl@0: /** sl@0: * Floating point utility that returns a Not a Number (NaN) value. sl@0: * @internal sl@0: */ sl@0: U_INTERNAL double U_EXPORT2 uprv_getNaN(void); sl@0: /** sl@0: * Floating point utility that returns an infinite value. sl@0: * @internal sl@0: */ sl@0: U_INTERNAL double U_EXPORT2 uprv_getInfinity(void); sl@0: sl@0: /** sl@0: * Floating point utility to truncate a double. sl@0: * @internal sl@0: */ sl@0: U_INTERNAL double U_EXPORT2 uprv_trunc(double d); sl@0: /** sl@0: * Floating point utility to calculate the floor of a double. sl@0: * @internal sl@0: */ sl@0: U_INTERNAL double U_EXPORT2 uprv_floor(double d); sl@0: /** sl@0: * Floating point utility to calculate the ceiling of a double. sl@0: * @internal sl@0: */ sl@0: U_INTERNAL double U_EXPORT2 uprv_ceil(double d); sl@0: /** sl@0: * Floating point utility to calculate the absolute value of a double. sl@0: * @internal sl@0: */ sl@0: U_INTERNAL double U_EXPORT2 uprv_fabs(double d); sl@0: /** sl@0: * Floating point utility to calculate the fractional and integer parts of a double. sl@0: * @internal sl@0: */ sl@0: U_INTERNAL double U_EXPORT2 uprv_modf(double d, double* pinteger); sl@0: /** sl@0: * Floating point utility to calculate the remainder of a double divided by another double. sl@0: * @internal sl@0: */ sl@0: U_INTERNAL double U_EXPORT2 uprv_fmod(double d, double y); sl@0: /** sl@0: * Floating point utility to calculate d to the power of exponent (d^exponent). sl@0: * @internal sl@0: */ sl@0: U_INTERNAL double U_EXPORT2 uprv_pow(double d, double exponent); sl@0: /** sl@0: * Floating point utility to calculate 10 to the power of exponent (10^exponent). sl@0: * @internal sl@0: */ sl@0: U_INTERNAL double U_EXPORT2 uprv_pow10(int32_t exponent); sl@0: /** sl@0: * Floating point utility to calculate the maximum value of two doubles. sl@0: * @internal sl@0: */ sl@0: U_INTERNAL double U_EXPORT2 uprv_fmax(double d, double y); sl@0: /** sl@0: * Floating point utility to calculate the minimum value of two doubles. sl@0: * @internal sl@0: */ sl@0: U_INTERNAL double U_EXPORT2 uprv_fmin(double d, double y); sl@0: /** sl@0: * Private utility to calculate the maximum value of two integers. sl@0: * @internal sl@0: */ sl@0: U_INTERNAL int32_t U_EXPORT2 uprv_max(int32_t d, int32_t y); sl@0: /** sl@0: * Private utility to calculate the minimum value of two integers. sl@0: * @internal sl@0: */ sl@0: U_INTERNAL int32_t U_EXPORT2 uprv_min(int32_t d, int32_t y); sl@0: sl@0: #if U_IS_BIG_ENDIAN sl@0: # define uprv_isNegative(number) (*((signed char *)&(number))<0) sl@0: #else sl@0: # define uprv_isNegative(number) (*((signed char *)&(number)+sizeof(number)-1)<0) sl@0: #endif sl@0: sl@0: /** sl@0: * Return the largest positive number that can be represented by an integer sl@0: * type of arbitrary bit length. sl@0: * @internal sl@0: */ sl@0: U_INTERNAL double U_EXPORT2 uprv_maxMantissa(void); sl@0: sl@0: /** sl@0: * Return the floor of the log base 10 of a given double. sl@0: * This method compensates for inaccuracies which arise naturally when sl@0: * computing logs, and always gives the correct value. The parameter sl@0: * must be positive and finite. sl@0: * (Thanks to Alan Liu for supplying this function.) sl@0: * sl@0: * @param d the double value to apply the common log function for. sl@0: * @return the log of value d. sl@0: * @internal sl@0: */ sl@0: U_INTERNAL int16_t U_EXPORT2 uprv_log10(double d); sl@0: sl@0: /** sl@0: * Floating point utility to calculate the logarithm of a double. sl@0: * @internal sl@0: */ sl@0: U_INTERNAL double U_EXPORT2 uprv_log(double d); sl@0: sl@0: /** sl@0: * Does common notion of rounding e.g. uprv_floor(x + 0.5); sl@0: * @param x the double number sl@0: * @return the rounded double sl@0: * @internal sl@0: */ sl@0: U_INTERNAL double U_EXPORT2 uprv_round(double x); sl@0: sl@0: #if 0 sl@0: /** sl@0: * Returns the number of digits after the decimal point in a double number x. sl@0: * sl@0: * @param x the double number sl@0: * @return the number of digits after the decimal point in a double number x. sl@0: * @internal sl@0: */ sl@0: /*U_INTERNAL int32_t U_EXPORT2 uprv_digitsAfterDecimal(double x);*/ sl@0: #endif sl@0: sl@0: /** sl@0: * Time zone utilities sl@0: * sl@0: * Wrappers for C runtime library functions relating to timezones. sl@0: * The t_tzset() function (similar to tzset) uses the current setting sl@0: * of the environment variable TZ to assign values to three global sl@0: * variables: daylight, timezone, and tzname. These variables have the sl@0: * following meanings, and are declared in <time.h>. sl@0: * sl@0: * daylight Nonzero if daylight-saving-time zone (DST) is specified sl@0: * in TZ; otherwise, 0. Default value is 1. sl@0: * timezone Difference in seconds between coordinated universal sl@0: * time and local time. E.g., -28,800 for PST (GMT-8hrs) sl@0: * tzname(0) Three-letter time-zone name derived from TZ environment sl@0: * variable. E.g., "PST". sl@0: * tzname(1) Three-letter DST zone name derived from TZ environment sl@0: * variable. E.g., "PDT". If DST zone is omitted from TZ, sl@0: * tzname(1) is an empty string. sl@0: * sl@0: * Notes: For example, to set the TZ environment variable to correspond sl@0: * to the current time zone in Germany, you can use one of the sl@0: * following statements: sl@0: * sl@0: * set TZ=GST1GDT sl@0: * set TZ=GST+1GDT sl@0: * sl@0: * If the TZ value is not set, t_tzset() attempts to use the time zone sl@0: * information specified by the operating system. Under Windows NT sl@0: * and Windows 95, this information is specified in the Control Panel's sl@0: * Date/Time application. sl@0: * @internal sl@0: */ sl@0: U_INTERNAL void U_EXPORT2 uprv_tzset(void); sl@0: sl@0: /** sl@0: * Difference in seconds between coordinated universal sl@0: * time and local time. E.g., -28,800 for PST (GMT-8hrs) sl@0: * @return the difference in seconds between coordinated universal time and local time. sl@0: * @internal sl@0: */ sl@0: U_INTERNAL int32_t U_EXPORT2 uprv_timezone(void); sl@0: sl@0: /** sl@0: * tzname(0) Three-letter time-zone name derived from TZ environment sl@0: * variable. E.g., "PST". sl@0: * tzname(1) Three-letter DST zone name derived from TZ environment sl@0: * variable. E.g., "PDT". If DST zone is omitted from TZ, sl@0: * tzname(1) is an empty string. sl@0: * @internal sl@0: */ sl@0: U_INTERNAL const char* U_EXPORT2 uprv_tzname(int n); sl@0: sl@0: /** sl@0: * Get UTC (GMT) time measured in milliseconds since 0:00 on 1/1/1970. sl@0: * @return the UTC time measured in milliseconds sl@0: * @internal sl@0: */ sl@0: U_INTERNAL UDate U_EXPORT2 uprv_getUTCtime(void); sl@0: sl@0: /** sl@0: * Determine whether a pathname is absolute or not, as defined by the platform. sl@0: * @param path Pathname to test sl@0: * @return TRUE if the path is absolute sl@0: * @internal (ICU 3.0) sl@0: */ sl@0: U_INTERNAL UBool U_EXPORT2 uprv_pathIsAbsolute(const char *path); sl@0: sl@0: /** sl@0: * Maximum value of a (void*) - use to indicate the limit of an 'infinite' buffer. sl@0: * In fact, buffer sizes must not exceed 2GB so that the difference between sl@0: * the buffer limit and the buffer start can be expressed in an int32_t. sl@0: * sl@0: * The definition of U_MAX_PTR must fulfill the following conditions: sl@0: * - return the largest possible pointer greater than base sl@0: * - return a valid pointer according to the machine architecture (AS/400, 64-bit, etc.) sl@0: * - avoid wrapping around at high addresses sl@0: * - make sure that the returned pointer is not farther from base than 0x7fffffff sl@0: * sl@0: * @param base The beginning of a buffer to find the maximum offset from sl@0: * @internal sl@0: */ sl@0: #ifndef U_MAX_PTR sl@0: # if defined(OS390) && !defined(_LP64) sl@0: /* We have 31-bit pointers. */ sl@0: # define U_MAX_PTR(base) ((void *)0x7fffffff) sl@0: # elif defined(OS400) sl@0: /* sl@0: * With the provided macro we should never be out of range of a given segment sl@0: * (a traditional/typical segment that is). Our segments have 5 bytes for the id sl@0: * and 3 bytes for the offset. The key is that the casting takes care of only sl@0: * retrieving the offset portion minus x1000. Hence, the smallest offset seen in sl@0: * a program is x001000 and when casted to an int would be 0. That's why we can sl@0: * only add 0xffefff. Otherwise, we would exceed the segment. sl@0: * sl@0: * Currently, 16MB is the current addressing limitation on as/400. This macro sl@0: * may eventually be changed to use 2GB addressability for the newer version of sl@0: * as/400 machines. sl@0: */ sl@0: # define U_MAX_PTR(base) ((void *)(((char *)base)-((int32_t)(base))+((int32_t)0xffefff))) sl@0: # else sl@0: # define U_MAX_PTR(base) ((void *)(((char *)(base)+0x7fffffffu) > (char *)(base) ? ((char *)(base)+0x7fffffffu) : (char *)-1)) sl@0: # endif sl@0: #endif sl@0: sl@0: #endif