HP C
Run-Time Library Reference Manual for OpenVMS Systems


Previous Contents Index


lgamma (ALPHA, I64)

Computes the logarithm of the gamma function.

Format

#include <math.h>

double lgamma (double x);

float lgammaf (float x);

long double lgammal (long double x);


Argument

x

A real number. x cannot be 0, a negative integer, or Infinity.

Description

The lgamma functions return the logarithm of the absolute value of gamma of x, or ln(|G(x)|), where G is the gamma function.

The sign of gamma of x is returned in the external integer variable signgam . The x argument cannot be 0, a negative integer, or Infinity.


Return Values

x The logarithmic gamma of the x argument.
-HUGE_VAL The x argument is a negative integer; errno is set to ERANGE.
NaN The x argument is NaN; errno is set to EDOM.
0 Underflow occurred; errno is set to ERANGE.
HUGE_VAL Overflow occurred; errno is set to ERANGE.

link

Creates a new link (directory entry) for an existing file. This function is supported only on volumes that have hard link counts enabled.

Format

#include <unistd.h>

link (const char *path1, const char *path2);


Arguments

path1

Pointer to a pathname naming an existing file.

path2

Pointer to a pathname naming the new directory entry to be created.

Description

The link function atomically creates a new link for the existing file, and the link count of the file is incremented by one.

The link function can be used on directory files.

If link fails, no link is created and the link count of the file remains unchanged.


Return Values

0 Successful completion.
- 1 Indicates an error. The function sets errno to one of the following values:
  • EEXIST -- The link named by path2 exists.
  • EFTYPE -- Wildcards appear in either path1 or path2.
  • EINVAL -- One or both arguments specify a syntactically invalid pathname.
  • ENAMETOOLONG -- The length of path1 or path2 exceeds PATH_MAX, or a pathname component is longer than NAME_MAX.
  • EXDEV -- The link named by path2 and the file named by path1 are on different devices.

localeconv

Sets the members of a structure of type struct lconv with values appropriate for formatting numeric quantities according to the rules of the current locale.

Format

#include <locale.h>

struct lconv *localeconv (void);


Description

The localeconv function returns a pointer to the lconv structure defined in the <locale.h> header file. This structure should not be modified by the program. It is overwritten by calls to localeconv , or by calls to the setlocale function that change the LC_NUMERIC, LC_MONETARY, or LC_ALL categories.

The members of the structure are:
Member Description
char *decimal_point The radix character.
char *thousands_sep The character used to separate groups of digits.
char *grouping The string that defines how digits are grouped in nonmonetary values.
char *int_curr_symbol The international currency symbol.
char *currency_symbol The local currency symbol.
char *mon_decimal_point The radix character used to format monetary values.
char *mon_thousands_sep The character used to separate groups of digits in monetary values.
char *mon_grouping The string that defines how digits are grouped in a monetary value.
char *positive_sign The string used to indicate a nonnegative monetary value.
char *negative_sign The string used to indicate a negative monetary value.
char int_frac_digits The number of digits displayed after the radix character in a monetary value formatted with the international currency symbol.
char frac_digits The number of digits displayed after the radix character in a monetary value.
char p_cs_precedes For positive monetary values, this is set to 1 if the local or international currency symbol precedes the number, and it is set to 0 if the symbol succeeds the number.
char p_sep_by_space For positive monetary values, this is set to 0 if there is no space between the currency symbol and the number. It is set to 1 if there is a space, and it is set to 2 if there is a space between the symbol and the sign string.
char n_cs_precedes For negative monetary values, this is set to 1 if the local or international currency symbol precedes the number, and it is set to 0 if the symbol succeeds the number.
char n_sep_by_space For negative monetary values, this is set to 0 if there is no space between the currency symbol and the number. It is set to 1 if there is a space, and it is set to 2 if there is a space between the symbol and the sign string.
char p_sign_posn An integer used to indicate where the positive_sign string should be placed for a nonnegative monetary quantity.
char n_sign_posn An integer used to indicate where the negative_sign string should be placed for a negative monetary quantity.

Members of the structure of type char * are pointers to strings, any of which (except decimal_point) can point to "", indicating that the associated value is not available in the current locale or is zero length. Members of the structure of type char are positive numbers, any of which can be CHAR_MAX, indicating that the associated value is not available in the current locale. CHAR_MAX is defined in the <limits.h> header file.

Be aware that the value of the CHAR_MAX macro in the <limits.h> header depends on whether the program is compiled with the /UNSIGNED_CHAR qualifier:

In /NOUNSIGNED_CHAR mode, the values of CHAR_MAX and SCHAR_MAX are the same; therefore, comparison with SCHAR_MAX gives correct results regardless of the /[NO]UNSIGNED_CHAR mode used.

The members grouping and mon_grouping point to a string that defines the size of each group of digits when formatting a number. Each group size is separated by a semicolon (;). For example, if grouping points to the string 5;3 and the thousands_sep character is a comma (,), the number 123450000 would be formatted as 1,234,50000.

The elements of grouping and mon_grouping are interpreted as follows:
Value Interpretation
CHAR_MAX No further grouping is performed.
0 The previous element is to be used repeatedly for the remainder of the digits.
other The integer value is the number of digits that comprise the current group. The next element is examined to determine the size of the next group of digits before the current group.

The values of p_sign_posn and n_sign_posn are interpreted as follows:
Value Interpretation
0 Parentheses surround the number and currency symbol.
1 The sign string precedes the number and currency symbol.
2 The sign string succeeds the number and currency symbol.
3 The sign string immediately precedes the number and currency symbol.
4 The sign string immediately succeeds the number and currency symbol.


Return Value

x Pointer to the lconv structure.

Example


#include <stdlib.h> 
#include <stdio.h> 
#include <limits.h> 
#include <locale.h> 
#include <string.h>                                        
 
/* The following test program will set up the British English   */ 
/* locale, and then extract the International Currency symbol   */ 
/* and the International Fractional Digits fields for this      */ 
/* locale and print them.                                       */ 
 
int main() 
{ 
    /* Declare variables                                        */ 
 
    char *return_val; 
    struct lconv *lconv_ptr; 
 
    /* Load a locale                                            */ 
 
    return_val = (char *) setlocale(LC_ALL, "en_GB.iso8859-1"); 
 
    /* Did the locale load successfully?                        */ 
 
    if (return_val == NULL) { 
 
        /* It failed to load the locale                         */ 
       printf("ERROR : The locale is unknown"); 
        exit(EXIT_FAILURE); 
    } 
 
    /*  Get the lconv structure from the locale                 */ 
 
    lconv_ptr = (struct lconv *) localeconv(); 
 
    /* Compare the international currency symbol string with an */ 
    /* empty string. If they are equal, then the international  */ 
    /* currency symbol is not defined in the locale.            */ 
 
    if (strcmp(lconv_ptr->int_curr_symbol, "")) { 
        printf("International Currency Symbol = %s\n", 
               lconv_ptr->int_curr_symbol); 
    } 
    else { 
        printf("International Currency Symbol ="); 
        printf("[Not available in this locale]\n"); 
    } 
 
    /* Compare International Fractional Digits with CHAR_MAX.   */ 
    /* If they are equal, then International Fractional Digits  */ 
    /* are not defined in this locale.                          */ 
 
    if ((unsigned char) (lconv_ptr->int_frac_digits) != CHAR_MAX) { 
        printf("International Fractional Digits = %d\n", 
               lconv_ptr->int_frac_digits); 
    } 
    else { 
        printf("International Fractional Digits ="); 
        printf("[Not available in this locale]\n"); 
    } 
} 

Running the example program produces the following result:


International Currency Symbol = GBP 
International Fractional Digits = 2 


localtime, localtime_r

Convert a time value to broken-down local time.

Format

#include <time.h>

struct tm *localtime (const time_t *timer);

struct tm *localtime_r (const time_t *timer, struct tm *result); (ISO POSIX-1)

Function Variants Compiling with the _DECC_V4_SOURCE and _VMS_V6_SOURCE feature-test macros defined enables a local-time-based entry point to the localtime_r function that is equivalent to the behavior before OpenVMS Version 7.0.

Arguments

timer

A pointer to a time in seconds since the Epoch. You can generate this time by using the time function or you can supply a time.

result

A pointer to a tm structure where the result is stored. The tm structure is defined in the <time.h> header file, and is also shown in Table REF-4.

Description

The localtime and localtime_r functions convert the time (in seconds since the Epoch) pointed to by timer into a broken-down time, expressed as a local time, and store it in a tm structure.

The difference between the localtime_r and localtime functions is that the former stores the result into a user-specified tm structure. The latter stores the result into thread-specific static memory allocated by the HP C RTL, and which is overwritten by subsequent calls to localtime ; you must make a copy if you want to save it.

On success, localtime returns a pointer to the tm structure; localtime_r returns its second argument. On failure, these functions return the NULL pointer.

The tm structure is defined in the <time.h> header file and described in Table REF-4.

Table REF-4 tm Structure
int tm_sec ; Seconds after the minute (0-60)
int tm_min ; Minutes after the hour (0-59)
int tm_hour ; Hours since midnight (0-23)
int tm_mday ; Day of the month (1-31)
int tm_mon ; Months since January (1-11)
int tm_year ; Years since 1900
int tm_wday ; Days since Sunday (0-6)
int tm_yday ; Days since January 1 (0-365)
int tm_isdst ; Daylight Savings Time flag
  • tm_isdst = 0 for Standard Time
  • tm_isdst = 1 for Daylight Time
long tm_gmtoff ;1 Seconds east of Greenwich (negative values indicate seconds west of Greenwich)
char * tm_zone ;1 Time zone string, for example "GMT"


1This field is an extention to the ANSI C structure. It is present unless you compile your program with /STANDARD=ANSI89 or with _DECC_V4_SOURCE defined.

The type time_t is defined in the <time.h> header file as follows:


typedef long int time_t 

Note

Generally speaking, UTC-based time functions can affect in-memory time-zone information, which is processwide data. However, if the system time zone remains the same during the execution of the application (which is the common case) and the cache of timezone files is enabled (which is the default), then the _r variant of the time functions asctime_r , ctime_r , gmtime_r and localtime_r , is both thread-safe and AST-reentrant.

If, however, the system time zone can change during the execution of the application or the cache of timezone files is not enabled, then both variants of the UTC-based time functions belong to the third class of functions, which are neither thread-safe nor AST-reentrant.

Return Values

x Pointer to a tm structure.
NULL Indicates failure.

log, log2, log10

Return the logarithm of their arguments.

Format

#include <math.h>

double log (double x);

float logf (float x); (ALPHA, I64)

long double logl (long double x); (ALPHA, I64)

double log2 (double x); (ALPHA, I64)

float log2f (float x); (ALPHA, I64)

long double log2l (long double x); (ALPHA, I64)

double log10 (double x);

float log10f (float x); (ALPHA, I64)

long double log10l (long double x); (ALPHA, I64)


Argument

x

A real number.

Description

The log functions compute the natural (base e) logarithm of x.

The log2 functions compute the base 2 logarithm of x.

The log10 functions compute the common (base 10) logarithm of x.


Return Values

x The logarithm of the argument (in the appropriate base).
- HUGE_VAL x is 0 ( errno is set to ERANGE), or x is negative ( errno is set to EDOM).
NaN x is NaN; errno is set to EDOM.

log1p (ALPHA, I64)

Computes ln(1+y) accurately.

Format

#include <math.h>

double log1p (double y);

float log1pf (float y);

long double log1pl (long double y);


Argument

y

A real number greater than - 1.

Description

The log1p functions compute ln(1+y) accurately, even for tiny y.

Return Values

x The natural logarithm of (1+ y).
- HUGE_VAL y is less than - 1 ( errno is set to EDOM), or y = - 1 ( errno is set to ERANGE).
NaN y is NaN; errno is set to EDOM.

logb (ALPHA, I64)

Returns the radix-independent exponent of the argument.

Format

#include <math.h>

double logb (double x);

float logbf (float x);

long double logbl (long double x);


Argument

x

A nonzero, real number.

Description

The logb functions return the exponent of x, which is the integral part of log2|x|, as a signed floating-point value, for nonzero x.

Return Values

x The exponent of x.
- HUGE_VAL x = 0.0; errno is set to EDOM.
+Infinity x is +Infinity or - Infinity.
NaN y is NaN; errno is set to EDOM.


Previous Next Contents Index