Commit b7c29c38 authored by Daniel Veillard's avatar Daniel Veillard

applied a trio update patch from Bjorn Reese which should work with MinGW

* trio.c trio.h triodef.h trionan.c trionan.h triop.h
  triostr.c triostr.h: applied a trio update patch from
  Bjorn Reese which should work with MinGW
Daniel
parent bd9afb52
Thu Sep 26 00:31:46 CEST 2002 Daniel Veillard <daniel@veillard.com>
* trio.c trio.h triodef.h trionan.c trionan.h triop.h
triostr.c triostr.h: applied a trio update patch from
Bjorn Reese which should work with MinGW
Thu Sep 26 00:21:18 CEST 2002 Daniel Veillard <daniel@veillard.com>
* tree.c: improving some documentation comments
......
......@@ -119,7 +119,7 @@ A:link, A:visited, A:active { text-decoration: underline }
Not Use libxml1</span></strong>, use libxml2</li>
<li>
<em>Where can I get libxml</em> ?
<p>The original distribution comes from <a href="ftp://rpmfind.net/pub/libxml/">rpmfind.net</a> or <a href="ftp://ftp.gnome.org/pub/GNOME/stable/sources/libxml/">gnome.org</a>
<p>The original distribution comes from <a href="ftp://rpmfind.net/pub/libxml/">rpmfind.net</a> or <a href="ftp://ftp.gnome.org/pub/GNOME/sources/libxml2/2.4/">gnome.org</a>
</p>
<p>Most Linux and BSD distributions include libxml, this is probably the
safer way for end-users to use libxml.</p>
......
......@@ -89,9 +89,8 @@ A:link, A:visited, A:active { text-decoration: underline }
</td></tr></table></td>
<td valign="top" bgcolor="#8b7765"><table border="0" cellspacing="0" cellpadding="1" width="100%"><tr><td><table border="0" cellspacing="0" cellpadding="1" width="100%" bgcolor="#000000"><tr><td><table border="0" cellpadding="3" cellspacing="1" width="100%"><tr><td bgcolor="#fffacd">
<p>The latest versions of libxml can be found on <a href="ftp://xmlsoft.org/">xmlsoft.org</a> (<a href="ftp://speakeasy.rpmfind.net/pub/libxml/">Seattle</a>, <a href="ftp://fr.rpmfind.net/pub/libxml/">France</a>) or on the <a href="ftp://ftp.gnome.org/pub/GNOME/MIRRORS.html">Gnome FTP server</a> either
as a <a href="ftp://ftp.gnome.org/pub/GNOME/stable/sources/libxml/">source
archive</a> or <a href="ftp://ftp.gnome.org/pub/GNOME/stable/redhat/i386/libxml/">RPM
packages</a>, Antonin Sprinzl also provide <a href="ftp://gd.tuwien.ac.at/pub/libxml/">a mirror in Austria</a>. (NOTE that
as a <a href="ftp://ftp.gnome.org/pub/GNOME/sources/libxml2/2.4/">source
archive</a>, Antonin Sprinzl also provide <a href="ftp://gd.tuwien.ac.at/pub/libxml/">a mirror in Austria</a>. (NOTE that
you need both the <a href="http://rpmfind.net/linux/RPM/libxml2.html">libxml(2)</a> and <a href="http://rpmfind.net/linux/RPM/libxml2-devel.html">libxml(2)-devel</a>
packages installed to compile applications using libxml.) <a href="mailto:igor@stud.fh-frankfurt.de">Igor Zlatkovic</a> is now the
maintainer of the Windows port, <a href="http://www.fh-frankfurt.de/~igor/projects/libxml/index.html">he
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -23,8 +23,14 @@
#define TRIO_TRIO_H
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#if defined(TRIO_COMPILER_ANCIENT)
# include <varargs.h>
#else
# include <stdarg.h>
#endif
#if !defined(WITHOUT_TRIO)
/*
* Use autoconf defines if present. Packages using trio must define
......@@ -34,22 +40,12 @@
# include <config.h>
#endif
#if !defined(WITHOUT_TRIO)
#include "triodef.h"
#ifdef __cplusplus
extern "C" {
#endif
/* make utility and C++ compiler in Windows NT fails to find this symbol */
#if defined(WIN32) && !defined(isascii)
# define isascii ((unsigned)(x) < 0x80)
#endif
/* Error macros */
#define TRIO_ERROR_CODE(x) ((-(x)) & 0x00FF)
#define TRIO_ERROR_POSITION(x) ((-(x)) >> 8)
#define TRIO_ERROR_NAME(x) trio_strerror(x)
/*
* Error codes.
*
......@@ -63,72 +59,95 @@ enum {
TRIO_EGAP = 5,
TRIO_ENOMEM = 6,
TRIO_ERANGE = 7,
TRIO_ERRNO = 8
TRIO_ERRNO = 8,
TRIO_ECUSTOM = 9
};
const char *trio_strerror(int);
/* Error macros */
#define TRIO_ERROR_CODE(x) ((-(x)) & 0x00FF)
#define TRIO_ERROR_POSITION(x) ((-(x)) >> 8)
#define TRIO_ERROR_NAME(x) trio_strerror(x)
typedef int (*trio_outstream_t) TRIO_PROTO((trio_pointer_t, int));
typedef int (*trio_instream_t) TRIO_PROTO((trio_pointer_t));
TRIO_CONST char *trio_strerror TRIO_PROTO((int));
/*************************************************************************
* Print Functions
*/
int trio_printf(const char *format, ...);
int trio_vprintf(const char *format, va_list args);
int trio_printfv(const char *format, void **args);
int trio_printf TRIO_PROTO((TRIO_CONST char *format, ...));
int trio_vprintf TRIO_PROTO((TRIO_CONST char *format, va_list args));
int trio_printfv TRIO_PROTO((TRIO_CONST char *format, void **args));
int trio_fprintf(FILE *file, const char *format, ...);
int trio_vfprintf(FILE *file, const char *format, va_list args);
int trio_fprintfv(FILE *file, const char *format, void **args);
int trio_fprintf TRIO_PROTO((FILE *file, TRIO_CONST char *format, ...));
int trio_vfprintf TRIO_PROTO((FILE *file, TRIO_CONST char *format, va_list args));
int trio_fprintfv TRIO_PROTO((FILE *file, TRIO_CONST char *format, void **args));
int trio_dprintf(int fd, const char *format, ...);
int trio_vdprintf(int fd, const char *format, va_list args);
int trio_dprintfv(int fd, const char *format, void **args);
int trio_dprintf TRIO_PROTO((int fd, TRIO_CONST char *format, ...));
int trio_vdprintf TRIO_PROTO((int fd, TRIO_CONST char *format, va_list args));
int trio_dprintfv TRIO_PROTO((int fd, TRIO_CONST char *format, void **args));
/* trio_sprintf(target, format, ...)
* trio_snprintf(target, maxsize, format, ...)
*
* Build 'target' according to 'format' and succesive
* arguments. This is equal to the sprintf() and
* snprintf() functions.
*/
int trio_sprintf(char *buffer, const char *format, ...);
int trio_vsprintf(char *buffer, const char *format, va_list args);
int trio_sprintfv(char *buffer, const char *format, void **args);
int trio_cprintf TRIO_PROTO((trio_outstream_t stream, trio_pointer_t closure,
TRIO_CONST char *format, ...));
int trio_vcprintf TRIO_PROTO((trio_outstream_t stream, trio_pointer_t closure,
TRIO_CONST char *format, va_list args));
int trio_cprintfv TRIO_PROTO((trio_outstream_t stream, trio_pointer_t closure,
TRIO_CONST char *format, void **args));
int trio_sprintf TRIO_PROTO((char *buffer, TRIO_CONST char *format, ...));
int trio_vsprintf TRIO_PROTO((char *buffer, TRIO_CONST char *format, va_list args));
int trio_sprintfv TRIO_PROTO((char *buffer, TRIO_CONST char *format, void **args));
int trio_snprintf(char *buffer, size_t max, const char *format, ...);
int trio_vsnprintf(char *buffer, size_t bufferSize, const char *format,
va_list args);
int trio_snprintfv(char *buffer, size_t bufferSize, const char *format,
void **args);
int trio_snprintf TRIO_PROTO((char *buffer, size_t max, TRIO_CONST char *format, ...));
int trio_vsnprintf TRIO_PROTO((char *buffer, size_t bufferSize, TRIO_CONST char *format,
va_list args));
int trio_snprintfv TRIO_PROTO((char *buffer, size_t bufferSize, TRIO_CONST char *format,
void **args));
int trio_snprintfcat(char *buffer, size_t max, const char *format, ...);
int trio_vsnprintfcat(char *buffer, size_t bufferSize, const char *format,
va_list args);
int trio_snprintfcat TRIO_PROTO((char *buffer, size_t max, TRIO_CONST char *format, ...));
int trio_vsnprintfcat TRIO_PROTO((char *buffer, size_t bufferSize, TRIO_CONST char *format,
va_list args));
char *trio_aprintf(const char *format, ...);
char *trio_vaprintf(const char *format, va_list args);
char *trio_aprintf TRIO_PROTO((TRIO_CONST char *format, ...));
char *trio_vaprintf TRIO_PROTO((TRIO_CONST char *format, va_list args));
int trio_asprintf(char **ret, const char *format, ...);
int trio_vasprintf(char **ret, const char *format, va_list args);
int trio_asprintf TRIO_PROTO((char **ret, TRIO_CONST char *format, ...));
int trio_vasprintf TRIO_PROTO((char **ret, TRIO_CONST char *format, va_list args));
/*************************************************************************
* Scan Functions
*/
int trio_scanf(const char *format, ...);
int trio_vscanf(const char *format, va_list args);
int trio_scanfv(const char *format, void **args);
int trio_scanf TRIO_PROTO((TRIO_CONST char *format, ...));
int trio_vscanf TRIO_PROTO((TRIO_CONST char *format, va_list args));
int trio_scanfv TRIO_PROTO((TRIO_CONST char *format, void **args));
int trio_fscanf TRIO_PROTO((FILE *file, TRIO_CONST char *format, ...));
int trio_vfscanf TRIO_PROTO((FILE *file, TRIO_CONST char *format, va_list args));
int trio_fscanfv TRIO_PROTO((FILE *file, TRIO_CONST char *format, void **args));
int trio_fscanf(FILE *file, const char *format, ...);
int trio_vfscanf(FILE *file, const char *format, va_list args);
int trio_fscanfv(FILE *file, const char *format, void **args);
int trio_dscanf TRIO_PROTO((int fd, TRIO_CONST char *format, ...));
int trio_vdscanf TRIO_PROTO((int fd, TRIO_CONST char *format, va_list args));
int trio_dscanfv TRIO_PROTO((int fd, TRIO_CONST char *format, void **args));
int trio_dscanf(int fd, const char *format, ...);
int trio_vdscanf(int fd, const char *format, va_list args);
int trio_dscanfv(int fd, const char *format, void **args);
int trio_cscanf TRIO_PROTO((trio_instream_t stream, trio_pointer_t closure,
TRIO_CONST char *format, ...));
int trio_vcscanf TRIO_PROTO((trio_instream_t stream, trio_pointer_t closure,
TRIO_CONST char *format, va_list args));
int trio_cscanfv TRIO_PROTO((trio_instream_t stream, trio_pointer_t closure,
TRIO_CONST char *format, void **args));
int trio_sscanf(const char *buffer, const char *format, ...);
int trio_vsscanf(const char *buffer, const char *format, va_list args);
int trio_sscanfv(const char *buffer, const char *format, void **args);
int trio_sscanf TRIO_PROTO((TRIO_CONST char *buffer, TRIO_CONST char *format, ...));
int trio_vsscanf TRIO_PROTO((TRIO_CONST char *buffer, TRIO_CONST char *format, va_list args));
int trio_sscanfv TRIO_PROTO((TRIO_CONST char *buffer, TRIO_CONST char *format, void **args));
/*************************************************************************
* Locale Functions
*/
void trio_locale_set_decimal_point TRIO_PROTO((char *decimalPoint));
void trio_locale_set_thousand_separator TRIO_PROTO((char *thousandSeparator));
void trio_locale_set_grouping TRIO_PROTO((char *grouping));
/*************************************************************************
* Renaming
......
......@@ -34,8 +34,12 @@
# define TRIO_COMPILER_XLC /* Workaround for old xlc */
#elif defined(__DECC) || defined(__DECCXX)
# define TRIO_COMPILER_DECC
#elif defined(__osf__) && defined(__LANGUAGE_C__)
# define TRIO_COMPILER_DECC /* Workaround for old DEC C compilers */
#elif defined(_MSC_VER)
# define TRIO_COMPILER_MSVC
#elif defined(__BORLANDC__)
# define TRIO_COMPILER_BCB
#endif
#if defined(unix) || defined(__unix) || defined(__unix__)
......@@ -61,9 +65,10 @@
# define TRIO_PLATFORM_MPEIX
#endif
#if defined(__STDC__)
# define TRIO_COMPILER_SUPPORTS_C90
#if defined(__STDC__) || defined(TRIO_COMPILER_MSVC)
# define TRIO_COMPILER_SUPPORTS_C89
# if defined(__STDC_VERSION__)
# define TRIO_COMPILER_SUPPORTS_C90
# if (__STDC_VERSION__ >= 199409L)
# define TRIO_COMPILER_SUPPORTS_C94
# endif
......@@ -84,6 +89,9 @@
# if (_XOPEN_VERSION >= 500)
# define TRIO_COMPILER_SUPPORTS_UNIX98
# endif
# if (_XOPEN_VERSION >= 600)
# define TRIO_COMPILER_SUPPORTS_UNIX01
# endif
#endif
/*************************************************************************
......@@ -97,22 +105,64 @@
# define TRIO_PRIVATE static
#endif
#if defined(TRIO_COMPILER_SUPPORTS_C90) || defined(__cplusplus)
# define TRIO_CONST const
# define TRIO_VOLATILE volatile
# define TRIO_POINTER void *
# define TRIO_PROTO(x) x
#else
#if !(defined(TRIO_COMPILER_SUPPORTS_C89) || defined(__cplusplus))
# define TRIO_COMPILER_ANCIENT
#endif
#if defined(TRIO_COMPILER_ANCIENT)
# define TRIO_CONST
# define TRIO_VOLATILE
# define TRIO_POINTER char *
# define TRIO_SIGNED
typedef double trio_long_double_t;
typedef char * trio_pointer_t;
# define TRIO_SUFFIX_LONG(x) x
# define TRIO_PROTO(x) ()
# define TRIO_NOARGS
# define TRIO_ARGS1(list,a1) list a1;
# define TRIO_ARGS2(list,a1,a2) list a1; a2;
# define TRIO_ARGS3(list,a1,a2,a3) list a1; a2; a3;
# define TRIO_ARGS4(list,a1,a2,a3,a4) list a1; a2; a3; a4;
# define TRIO_ARGS5(list,a1,a2,a3,a4,a5) list a1; a2; a3; a4; a5;
# define TRIO_ARGS6(list,a1,a2,a3,a4,a5,a6) list a1; a2; a3; a4; a5; a6;
# define TRIO_VARGS2(list,a1,a2) list a1; a2
# define TRIO_VARGS3(list,a1,a2,a3) list a1; a2; a3
# define TRIO_VARGS4(list,a1,a2,a3,a4) list a1; a2; a3; a4
# define TRIO_VARGS5(list,a1,a2,a3,a4,a5) list a1; a2; a3; a4; a5
# define TRIO_VA_DECL va_dcl
# define TRIO_VA_START(x,y) va_start((x))
# define TRIO_VA_END(x) va_end(x)
#else /* ANSI C */
# define TRIO_CONST const
# define TRIO_VOLATILE volatile
# define TRIO_SIGNED signed
typedef long double trio_long_double_t;
typedef void * trio_pointer_t;
# define TRIO_SUFFIX_LONG(x) x ## L
# define TRIO_PROTO(x) x
# define TRIO_NOARGS void
# define TRIO_ARGS1(list,a1) (a1)
# define TRIO_ARGS2(list,a1,a2) (a1,a2)
# define TRIO_ARGS3(list,a1,a2,a3) (a1,a2,a3)
# define TRIO_ARGS4(list,a1,a2,a3,a4) (a1,a2,a3,a4)
# define TRIO_ARGS5(list,a1,a2,a3,a4,a5) (a1,a2,a3,a4,a5)
# define TRIO_ARGS6(list,a1,a2,a3,a4,a5,a6) (a1,a2,a3,a4,a5,a6)
# define TRIO_VARGS2 TRIO_ARGS2
# define TRIO_VARGS3 TRIO_ARGS3
# define TRIO_VARGS4 TRIO_ARGS4
# define TRIO_VARGS5 TRIO_ARGS5
# define TRIO_VA_DECL ...
# define TRIO_VA_START(x,y) va_start((x),(y))
# define TRIO_VA_END(x) va_end(x)
#endif
#if defined(TRIO_COMPILER_SUPPORTS_C99) || defined(__cplusplus)
# define TRIO_INLINE inline
#elif defined(TRIO_COMPILER_GCC)
# define TRIO_INLINE __inline__
#elif defined(TRIO_COMPILER_MSVC)
# define TRIO_INLINE _inline
#elif defined(TRIO_COMPILER_BCB)
# define TRIO_INLINE __inline
#else
# define TRIO_INLINE
#endif
......
......@@ -29,40 +29,13 @@
* 2. Use IEEE 754 bit-patterns if possible.
* 3. Use platform-specific techniques.
*
* This program has been tested on the following platforms (in
* alphabetic order)
*
* OS CPU Compiler
* -------------------------------------------------
* AIX 4.1.4 PowerPC gcc
* Darwin 1.3.7 PowerPC gcc
* FreeBSD 2.2 x86 gcc
* FreeBSD 3.3 x86 gcc
* FreeBSD 4.3 x86 gcc
* FreeBSD 4.3 Alpha gcc
* HP-UX 10.20 PA-RISC gcc
* HP-UX 10.20 PA-RISC HP C++
* IRIX 6.5 MIPS MIPSpro C
* Linux 2.2 x86 gcc
* Linux 2.2 Alpha gcc
* Linux 2.4 IA64 gcc
* Linux 2.4 StrongARM gcc
* NetBSD 1.4 x86 gcc
* NetBSD 1.4 StrongARM gcc
* NetBSD 1.5 Alpha gcc
* OpenVMS 7.1 Alpha DEC C 6.0
* RISC OS 4 StrongARM Norcroft C
* Solaris 2.5.1 x86 gcc
* Solaris 2.5.1 Sparc gcc
* Solaris 2.6 Sparc WorkShop 4.2
* Solaris 8 Sparc Forte C 6
* Tru64 4.0D Alpha gcc
* Tru64 5.1 Alpha gcc
* WinNT x86 MSVC 5.0 & 6.0
*
************************************************************************/
static const char rcsid[] = "@(#)$Id$";
/*
* TODO:
* o Put all the magic into trio_fpclassify_and_signbit(), and use this from
* trio_isnan() etc.
*/
/*************************************************************************
* Include files
......@@ -102,7 +75,9 @@ static const char rcsid[] = "@(#)$Id$";
# if defined(TRIO_PLATFORM_VMS)
# error "Must be compiled with option /IEEE_MODE=UNDERFLOW_TO_ZERO/FLOAT=IEEE"
# else
# error "Must be compiled with option -ieee"
# if !defined(_CFE)
# error "Must be compiled with option -ieee"
# endif
# endif
# elif defined(TRIO_COMPILER_GCC) && (defined(__osf__) || defined(__linux__))
# error "Must be compiled with option -mieee"
......@@ -128,9 +103,11 @@ static const char rcsid[] = "@(#)$Id$";
/*************************************************************************
* Data
* Constants
*/
static TRIO_CONST char rcsid[] = "@(#)$Id$";
#if defined(USE_IEEE_754)
/*
......@@ -187,7 +164,9 @@ static TRIO_CONST unsigned char ieee_754_qnan_array[] = {
* trio_make_double
*/
TRIO_PRIVATE double
trio_make_double(TRIO_CONST unsigned char *values)
trio_make_double
TRIO_ARGS1((values),
TRIO_CONST unsigned char *values)
{
TRIO_VOLATILE double result;
int i;
......@@ -202,8 +181,10 @@ trio_make_double(TRIO_CONST unsigned char *values)
* trio_is_special_quantity
*/
TRIO_PRIVATE int
trio_is_special_quantity(double number,
int *has_mantissa)
trio_is_special_quantity
TRIO_ARGS2((number, has_mantissa),
double number,
int *has_mantissa)
{
unsigned int i;
unsigned char current;
......@@ -224,7 +205,9 @@ trio_is_special_quantity(double number,
* trio_is_negative
*/
TRIO_PRIVATE int
trio_is_negative(double number)
trio_is_negative
TRIO_ARGS1((number),
double number)
{
unsigned int i;
int is_negative = TRIO_FALSE;
......@@ -236,14 +219,25 @@ trio_is_negative(double number)
return is_negative;
}
#endif /* USE_IEEE_754 */
/**
Generate negative zero.
@return Floating-point representation of negative zero.
*/
TRIO_PUBLIC double
trio_nzero(void)
trio_nzero(TRIO_NOARGS)
{
#if defined(USE_IEEE_754)
return trio_make_double(ieee_754_negzero_array);
}
#endif /* USE_IEEE_754 */
#else
TRIO_VOLATILE double zero = 0.0;
return -zero;
#endif
}
/**
Generate positive infinity.
......@@ -251,7 +245,7 @@ trio_nzero(void)
@return Floating-point representation of positive infinity.
*/
TRIO_PUBLIC double
trio_pinf(void)
trio_pinf(TRIO_NOARGS)
{
/* Cache the result */
static double result = 0.0;
......@@ -295,7 +289,7 @@ trio_pinf(void)
@return Floating-point value of negative infinity.
*/
TRIO_PUBLIC double
trio_ninf(void)
trio_ninf(TRIO_NOARGS)
{
static double result = 0.0;
......@@ -316,7 +310,7 @@ trio_ninf(void)
@return Floating-point representation of NaN.
*/
TRIO_PUBLIC double
trio_nan(void)
trio_nan(TRIO_NOARGS)
{
/* Cache the result */
static double result = 0.0;
......@@ -364,9 +358,12 @@ trio_nan(void)
@return Boolean value indicating whether or not the number is a NaN.
*/
TRIO_PUBLIC int
trio_isnan(TRIO_VOLATILE double number)
trio_isnan
TRIO_ARGS1((number),
double number)
{
#if defined(isnan) || defined(TRIO_COMPILER_SUPPORTS_UNIX95)
#if (defined(TRIO_COMPILER_SUPPORTS_C99) && defined(isnan)) \
|| defined(TRIO_COMPILER_SUPPORTS_UNIX95)
/*
* C99 defines isnan() as a macro. UNIX95 defines isnan() as a
* function. This function was already present in XPG4, but this
......@@ -407,7 +404,7 @@ trio_isnan(TRIO_VOLATILE double number)
status = (/*
* NaN is the only number which does not compare to itself
*/
(number != number) ||
((TRIO_VOLATILE double)number != (TRIO_VOLATILE double)number) ||
/*
* Fallback solution if NaN compares to NaN
*/
......@@ -431,7 +428,9 @@ trio_isnan(TRIO_VOLATILE double number)
@return 1 if positive infinity, -1 if negative infinity, 0 otherwise.
*/
TRIO_PUBLIC int
trio_isinf(TRIO_VOLATILE double number)
trio_isinf
TRIO_ARGS1((number),
double number)
{
#if defined(TRIO_COMPILER_DECC)
/*
......@@ -441,12 +440,14 @@ trio_isinf(TRIO_VOLATILE double number)
return ((fp_class(number) == FP_POS_INF)
? 1
: ((fp_class(number) == FP_NEG_INF) ? -1 : 0));
#elif defined(isinf)
/*
* C99 defines isinf() as a macro.
*/
return isinf(number);
return isinf(number)
? ((number > 0.0) ? 1 : -1)
: 0;
#elif defined(TRIO_COMPILER_MSVC)
/*
......@@ -503,9 +504,11 @@ trio_isinf(TRIO_VOLATILE double number)
@return Boolean value indicating whether or not the number is a finite.
*/
TRIO_PUBLIC int
trio_isfinite(TRIO_VOLATILE double number)
trio_isfinite
TRIO_ARGS1((number),
double number)
{
#if defined(isfinite)
#if defined(TRIO_COMPILER_SUPPORTS_C99) && defined(isfinite)
/*
* C99 defines isfinite() as a macro.
*/
......@@ -538,9 +541,11 @@ trio_isfinite(TRIO_VOLATILE double number)
/*
* The sign of NaN is always false
*/
TRIO_PRIVATE int
trio_fpclass(TRIO_VOLATILE double number,
int *is_negative)
TRIO_PUBLIC int
trio_fpclassify_and_signbit
TRIO_ARGS2((number, is_negative),
double number,
int *is_negative)
{
#if defined(fpclassify) && defined(signbit)
/*
......@@ -637,7 +642,46 @@ trio_fpclass(TRIO_VOLATILE double number,
*is_negative = (number < 0.0);
return TRIO_FP_NORMAL;
}
#elif defined(FP_PLUS_NORM) || defined(__hpux)
/*
* HP-UX 9.x and 10.x have an fpclassify() function, that is different
* from the C99 fpclassify() macro supported on HP-UX 11.x.
*/
switch (fpclassify(number)) {
case FP_QNAN:
case FP_SNAN:
*is_negative = TRIO_FALSE;
return TRIO_FP_NAN;
case FP_PLUS_INF:
*is_negative = TRIO_FALSE;
return TRIO_FP_INFINITE;
case FP_MINUS_INF:
*is_negative = TRIO_TRUE;
return TRIO_FP_INFINITE;
case FP_PLUS_DENORM:
*is_negative = TRIO_FALSE;
return TRIO_FP_SUBNORMAL;
case FP_MINUS_DENORM:
*is_negative = TRIO_TRUE;
return TRIO_FP_SUBNORMAL;
case FP_PLUS_ZERO:
*is_negative = TRIO_FALSE;
return TRIO_FP_ZERO;
case FP_MINUS_ZERO:
*is_negative = TRIO_TRUE;
return TRIO_FP_ZERO;
case FP_PLUS_NORM:
*is_negative = TRIO_FALSE;
return TRIO_FP_NORMAL;
case FP_MINUS_NORM:
*is_negative = TRIO_TRUE;
return TRIO_FP_NORMAL;
default:
assert(0);
}
#else
/*
* Fallback solution.
......@@ -687,11 +731,13 @@ trio_fpclass(TRIO_VOLATILE double number,
sign bit set (i.e. is negative).
*/
TRIO_PUBLIC int
trio_signbit(TRIO_VOLATILE double number)
trio_signbit
TRIO_ARGS1((number),
double number)
{
int is_negative;
(void)trio_fpclass(number, &is_negative);
(void)trio_fpclassify_and_signbit(number, &is_negative);
return is_negative;
}
......@@ -702,11 +748,13 @@ trio_signbit(TRIO_VOLATILE double number)
@return Enumerable value indicating the class of @p number
*/
TRIO_PUBLIC int
trio_fpclassify(TRIO_VOLATILE double number)
trio_fpclassify
TRIO_ARGS1((number),
double number)
{
int dummy;
return trio_fpclass(number, &dummy);
return trio_fpclassify_and_signbit(number, &dummy);
}
......@@ -723,7 +771,10 @@ trio_fpclassify(TRIO_VOLATILE double number)
#if defined(STANDALONE)
# include <stdio.h>
static const char *getClassification(int type)
static TRIO_CONST char *
getClassification
TRIO_ARGS1((type)
int type)
{
switch (type) {
case TRIO_FP_INFINITE:
......@@ -741,7 +792,11 @@ static const char *getClassification(int type)
}
}
static void print_class(const char *prefix, double number)
static void
print_class
TRIO_ARGS2((prefix, number)
TRIO_CONST char *prefix,
double number)
{
printf("%-6s: %s %-15s %g\n",
prefix,
......@@ -750,13 +805,13 @@ static void print_class(const char *prefix, double number)
number);
}
int main(void)
int main(TRIO_NOARGS)
{
double my_nan;
double my_pinf;
double my_ninf;
# if defined(TRIO_PLATFORM_UNIX)
void (*signal_handler)(int);
void (*signal_handler) TRIO_PROTO((int));
# endif
my_nan = trio_nan();
......
......@@ -35,39 +35,44 @@ enum {
/*
* Return NaN (Not-a-Number).
*/
TRIO_PUBLIC double trio_nan(void);
TRIO_PUBLIC double trio_nan TRIO_PROTO((void));
/*
* Return positive infinity.
*/
TRIO_PUBLIC double trio_pinf(void);
TRIO_PUBLIC double trio_pinf TRIO_PROTO((void));
/*
* Return negative infinity.
*/
TRIO_PUBLIC double trio_ninf(void);
TRIO_PUBLIC double trio_ninf TRIO_PROTO((void));
/*
* Return negative zero.
*/
TRIO_PUBLIC double trio_nzero TRIO_PROTO((TRIO_NOARGS));
/*
* If number is a NaN return non-zero, otherwise return zero.
*/
TRIO_PUBLIC int trio_isnan(double number);
TRIO_PUBLIC int trio_isnan TRIO_PROTO((double number));
/*
* If number is positive infinity return 1, if number is negative
* infinity return -1, otherwise return 0.
*/
TRIO_PUBLIC int trio_isinf(double number);
TRIO_PUBLIC int trio_isinf TRIO_PROTO((double number));
/*
* If number is finite return non-zero, otherwise return zero.
*/
TRIO_PUBLIC int trio_isfinite(double number);
TRIO_PUBLIC int trio_isfinite TRIO_PROTO((double number));
TRIO_PUBLIC int trio_signbit(double number);
TRIO_PUBLIC int trio_signbit TRIO_PROTO((double number));
TRIO_PUBLIC int trio_fpclassify(double number);
TRIO_PUBLIC int trio_fpclassify TRIO_PROTO((double number));
TRIO_PUBLIC double trio_nzero(void);
TRIO_PUBLIC int trio_fpclassify_and_signbit TRIO_PROTO((double number, int *is_negative));
#ifdef __cplusplus
}
......
......@@ -26,8 +26,14 @@
#ifndef TRIO_TRIOP_H
#define TRIO_TRIOP_H
#include "triodef.h"
#include <stdlib.h>
#include <stdarg.h>
#if defined(TRIO_COMPILER_ANCIENT)
# include <varargs.h>
#else
# include <stdarg.h>
#endif
#ifdef __cplusplus
extern "C" {
......@@ -71,70 +77,71 @@ extern "C" {
# define TRIO_FREE(x) free(x)