17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 77c478bd9Sstevel@tonic-gate * with the License. 87c478bd9Sstevel@tonic-gate * 97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 127c478bd9Sstevel@tonic-gate * and limitations under the License. 137c478bd9Sstevel@tonic-gate * 147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 197c478bd9Sstevel@tonic-gate * 207c478bd9Sstevel@tonic-gate * CDDL HEADER END 217c478bd9Sstevel@tonic-gate */ 227c478bd9Sstevel@tonic-gate /* Copyright (c) 1988 AT&T */ 237c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 247c478bd9Sstevel@tonic-gate 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate /* 27*b59b3655SGarrett D'Amore * Copyright 2014 Garrett D'Amore <garrett@damore.org> 28*b59b3655SGarrett D'Amore * 297c478bd9Sstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 307c478bd9Sstevel@tonic-gate * Use is subject to license terms. 317c478bd9Sstevel@tonic-gate */ 327c478bd9Sstevel@tonic-gate 337c478bd9Sstevel@tonic-gate #ifndef _VALUES_H 347c478bd9Sstevel@tonic-gate #define _VALUES_H 357c478bd9Sstevel@tonic-gate 367c478bd9Sstevel@tonic-gate #include <sys/isa_defs.h> 377c478bd9Sstevel@tonic-gate 387c478bd9Sstevel@tonic-gate #ifdef __cplusplus 397c478bd9Sstevel@tonic-gate extern "C" { 407c478bd9Sstevel@tonic-gate #endif 417c478bd9Sstevel@tonic-gate 427c478bd9Sstevel@tonic-gate /* 437c478bd9Sstevel@tonic-gate * These values work with any binary representation of integers 447c478bd9Sstevel@tonic-gate * where the high-order bit contains the sign. 457c478bd9Sstevel@tonic-gate */ 467c478bd9Sstevel@tonic-gate 477c478bd9Sstevel@tonic-gate /* a number used normally for size of a shift */ 487c478bd9Sstevel@tonic-gate #define BITSPERBYTE 8 497c478bd9Sstevel@tonic-gate 507c478bd9Sstevel@tonic-gate #define BITS(type) (BITSPERBYTE * (long)sizeof (type)) 517c478bd9Sstevel@tonic-gate 527c478bd9Sstevel@tonic-gate /* short, regular and long ints with only the high-order bit turned on */ 537c478bd9Sstevel@tonic-gate #define HIBITS ((short)(1 << (BITS(short) - 1))) 547c478bd9Sstevel@tonic-gate 557c478bd9Sstevel@tonic-gate #define HIBITI (1U << (BITS(int) - 1)) 567c478bd9Sstevel@tonic-gate #define HIBITL (1UL << (BITS(long) - 1)) 577c478bd9Sstevel@tonic-gate 587c478bd9Sstevel@tonic-gate /* largest short, regular and long int */ 597c478bd9Sstevel@tonic-gate #define MAXSHORT ((short)~HIBITS) 607c478bd9Sstevel@tonic-gate #define MAXINT ((int)(~HIBITI)) 617c478bd9Sstevel@tonic-gate #define MAXLONG ((long)(~HIBITL)) 627c478bd9Sstevel@tonic-gate 637c478bd9Sstevel@tonic-gate /* 647c478bd9Sstevel@tonic-gate * various values that describe the binary floating-point representation 657c478bd9Sstevel@tonic-gate * _EXPBASE - the exponent base 667c478bd9Sstevel@tonic-gate * DMAXEXP - the maximum exponent of a double (as returned by frexp()) 677c478bd9Sstevel@tonic-gate * FMAXEXP - the maximum exponent of a float (as returned by frexp()) 687c478bd9Sstevel@tonic-gate * DMINEXP - the minimum exponent of a double (as returned by frexp()) 697c478bd9Sstevel@tonic-gate * FMINEXP - the minimum exponent of a float (as returned by frexp()) 707c478bd9Sstevel@tonic-gate * MAXDOUBLE - the largest double 717c478bd9Sstevel@tonic-gate * ((_EXPBASE ** DMAXEXP) * (1 - (_EXPBASE ** -DSIGNIF))) 727c478bd9Sstevel@tonic-gate * MAXFLOAT - the largest float 737c478bd9Sstevel@tonic-gate * ((_EXPBASE ** FMAXEXP) * (1 - (_EXPBASE ** -FSIGNIF))) 747c478bd9Sstevel@tonic-gate * MINDOUBLE - the smallest double (_EXPBASE ** (DMINEXP - 1)) 757c478bd9Sstevel@tonic-gate * MINFLOAT - the smallest float (_EXPBASE ** (FMINEXP - 1)) 767c478bd9Sstevel@tonic-gate * DSIGNIF - the number of significant bits in a double 777c478bd9Sstevel@tonic-gate * FSIGNIF - the number of significant bits in a float 787c478bd9Sstevel@tonic-gate * DMAXPOWTWO - the largest power of two exactly representable as a double 797c478bd9Sstevel@tonic-gate * FMAXPOWTWO - the largest power of two exactly representable as a float 807c478bd9Sstevel@tonic-gate * _IEEE - 1 if IEEE standard representation is used 817c478bd9Sstevel@tonic-gate * _DEXPLEN - the number of bits for the exponent of a double 827c478bd9Sstevel@tonic-gate * _FEXPLEN - the number of bits for the exponent of a float 837c478bd9Sstevel@tonic-gate * _HIDDENBIT - 1 if high-significance bit of mantissa is implicit 847c478bd9Sstevel@tonic-gate * LN_MAXDOUBLE - the natural log of the largest double -- log(MAXDOUBLE) 857c478bd9Sstevel@tonic-gate * LN_MINDOUBLE - the natural log of the smallest double -- log(MINDOUBLE) 867c478bd9Sstevel@tonic-gate * LN_MAXFLOAT - the natural log of the largest float -- log(MAXFLOAT) 877c478bd9Sstevel@tonic-gate * LN_MINFLOAT - the natural log of the smallest float -- log(MINFLOAT) 887c478bd9Sstevel@tonic-gate */ 897c478bd9Sstevel@tonic-gate 907c478bd9Sstevel@tonic-gate /* 917c478bd9Sstevel@tonic-gate * Currently, only IEEE-754 format is supported. 927c478bd9Sstevel@tonic-gate */ 937c478bd9Sstevel@tonic-gate #if defined(_IEEE_754) 947c478bd9Sstevel@tonic-gate #define MAXDOUBLE 1.79769313486231570e+308 957c478bd9Sstevel@tonic-gate #define MAXFLOAT ((float)3.40282346638528860e+38) 967c478bd9Sstevel@tonic-gate #define MINDOUBLE 4.94065645841246544e-324 977c478bd9Sstevel@tonic-gate #define MINFLOAT ((float)1.40129846432481707e-45) 987c478bd9Sstevel@tonic-gate #define _IEEE 1 997c478bd9Sstevel@tonic-gate #define _DEXPLEN 11 1007c478bd9Sstevel@tonic-gate #define _HIDDENBIT 1 1017c478bd9Sstevel@tonic-gate #define _LENBASE 1 1027c478bd9Sstevel@tonic-gate #define DMINEXP (-(DMAXEXP + DSIGNIF - _HIDDENBIT - 3)) 1037c478bd9Sstevel@tonic-gate #define FMINEXP (-(FMAXEXP + FSIGNIF - _HIDDENBIT - 3)) 1047c478bd9Sstevel@tonic-gate #else 1057c478bd9Sstevel@tonic-gate /* #error is strictly ansi-C, but works as well as anything for K&R systems. */ 1067c478bd9Sstevel@tonic-gate #error "ISA not supported" 1077c478bd9Sstevel@tonic-gate #endif 1087c478bd9Sstevel@tonic-gate 1097c478bd9Sstevel@tonic-gate #define _EXPBASE (1 << _LENBASE) 1107c478bd9Sstevel@tonic-gate #define _FEXPLEN 8 1117c478bd9Sstevel@tonic-gate #define DSIGNIF (BITS(double) - _DEXPLEN + _HIDDENBIT - 1) 1127c478bd9Sstevel@tonic-gate #define FSIGNIF (BITS(float) - _FEXPLEN + _HIDDENBIT - 1) 1137c478bd9Sstevel@tonic-gate #define DMAXPOWTWO ((double)(1 << (BITS(int) - 2)) * \ 1147c478bd9Sstevel@tonic-gate (1 << (DSIGNIF - BITS(int) + 1))) 1157c478bd9Sstevel@tonic-gate #define FMAXPOWTWO ((float)(1 << (FSIGNIF - 1))) 1167c478bd9Sstevel@tonic-gate #define DMAXEXP ((1 << (_DEXPLEN - 1)) - 1 + _IEEE) 1177c478bd9Sstevel@tonic-gate #define FMAXEXP ((1 << (_FEXPLEN - 1)) - 1 + _IEEE) 1187c478bd9Sstevel@tonic-gate #define LN_MAXDOUBLE (M_LN2 * DMAXEXP) 1197c478bd9Sstevel@tonic-gate #define LN_MAXFLOAT (float)(M_LN2 * FMAXEXP) 1207c478bd9Sstevel@tonic-gate #define LN_MINDOUBLE (M_LN2 * (DMINEXP - 1)) 1217c478bd9Sstevel@tonic-gate #define LN_MINFLOAT (float)(M_LN2 * (FMINEXP - 1)) 1227c478bd9Sstevel@tonic-gate #define H_PREC (DSIGNIF % 2 ? (1 << DSIGNIF/2) * M_SQRT2 : 1 << DSIGNIF/2) 1237c478bd9Sstevel@tonic-gate #define FH_PREC \ 1247c478bd9Sstevel@tonic-gate (float)(FSIGNIF % 2 ? (1 << FSIGNIF/2) * M_SQRT2 : 1 << FSIGNIF/2) 1257c478bd9Sstevel@tonic-gate #define X_EPS (1.0/H_PREC) 1267c478bd9Sstevel@tonic-gate #define FX_EPS (float)((float)1.0/FH_PREC) 1277c478bd9Sstevel@tonic-gate #define X_PLOSS ((double)(int)(M_PI * H_PREC)) 1287c478bd9Sstevel@tonic-gate #define FX_PLOSS ((float)(int)(M_PI * FH_PREC)) 1297c478bd9Sstevel@tonic-gate #define X_TLOSS (M_PI * DMAXPOWTWO) 1307c478bd9Sstevel@tonic-gate #define FX_TLOSS (float)(M_PI * FMAXPOWTWO) 1317c478bd9Sstevel@tonic-gate #define M_LN2 0.69314718055994530942 1327c478bd9Sstevel@tonic-gate #define M_PI 3.14159265358979323846 1337c478bd9Sstevel@tonic-gate #define M_SQRT2 1.41421356237309504880 1347c478bd9Sstevel@tonic-gate #define MAXBEXP DMAXEXP /* for backward compatibility */ 1357c478bd9Sstevel@tonic-gate #define MINBEXP DMINEXP /* for backward compatibility */ 1367c478bd9Sstevel@tonic-gate #define MAXPOWTWO DMAXPOWTWO /* for backward compatibility */ 1377c478bd9Sstevel@tonic-gate 1387c478bd9Sstevel@tonic-gate #ifdef __cplusplus 1397c478bd9Sstevel@tonic-gate } 1407c478bd9Sstevel@tonic-gate #endif 1417c478bd9Sstevel@tonic-gate 1427c478bd9Sstevel@tonic-gate #endif /* _VALUES_H */ 143