Date: Sun, 30 Mar 2003 17:56:46 +0200 From: Alexander Leidinger <Alexander@Leidinger.net> To: ppc@freebsd.org, das@freebsd.org Cc: cvs-all@freebsd.org Subject: Re: cvs commit: src/sys/ia64/include float.h Message-ID: <20030330175646.281097ad.Alexander@Leidinger.net> In-Reply-To: <20030327204935.GA18134@HAL9000.homeunix.com> References: <200303272038.h2RKcM7L096560@repoman.freebsd.org> <20030327204935.GA18134@HAL9000.homeunix.com>
next in thread | previous in thread | raw e-mail | index | archive | help
[-- Attachment #1 --]
On Thu, 27 Mar 2003 12:49:35 -0800
David Schultz <das@freebsd.org> wrote:
> Thus spake David Schultz <das@FreeBSD.org>:
> > das 2003/03/27 12:38:22 PST
> >
> > FreeBSD src repository
> >
> > Modified files:
> > sys/ia64/include float.h
> > Log:
> > Correct LDBL_* constants based on values from i386.
> >
> > Revision Changes Path
> > 1.4 +9 -9 src/sys/ia64/include/float.h
>
> BTW, this needs to be fixed for powerpc as well. Thus far I have
> been assuming powerpc uses quad format (128 bits) for long doubles
> based on some documentation on developer.apple.com. It would be
> nice if someone could confirm/deny that.
Attached is a test for 32 and 64 bit ieee values (edge cases). The *_MIN
values (or my test program) at least on i386 machines are wrong.
Bye,
Alexander.
--
It's not a bug, it's tradition!
http://www.Leidinger.net Alexander @ Leidinger.net
GPG fingerprint = C518 BC70 E67F 143F BE91 3365 79E2 9C60 B006 3FE7
[-- Attachment #2 --]
/*
* Copyright (c) 2002 Alexander Leidinger <netchild@FreeBSD.org>. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met: 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer, without
* modification, immediately at the beginning of the file. 2. Redistributions
* in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#include <stdio.h>
#include <stdint.h>
#include <float.h>
int test_32(void);
int test_64(void);
int
main(void)
{
return test_32() | test_64();
}
int
test_32(void)
{
uint32_t hack32;
float result32;
int retval = 0;
if (4 != sizeof(float)) {
puts("sizeof float != 4, can not test");
return 1;
}
/*
* 1 bit sign 8 bit exponent 23 bit mantissa
*/
puts("FLOAT:");
#define TOF(x) (*(float *)&(x))
hack32 = 0x7f800000;
result32 = TOF(hack32);
printf(" Testing for inf: %f\n", result32);
#if 0
/* XXX: how is the damn name of this... */
if (result32 != inf)
retval = 1;
#endif
hack32 = 0xff800000;
result32 = TOF(hack32);
printf(" Testing for -inf: %f\n", result32);
hack32 = 0x7f7fffff;
result32 = TOF(hack32);
if (FLT_MAX != result32) {
printf(" Testing for FLT_MAX: FAILED (%.37e)!\n", result32);
retval = 1;
} else {
printf(" Testing for FLT_MAX: %.37e\n", result32);
}
hack32 = 0xff7fffff;
result32 = TOF(hack32);
if (-FLT_MAX != result32) {
printf(" Testing for -FLT_MAX: FAILED (%.37e)!\n", result32);
retval = 1;
} else {
printf(" Testing for -FLT_MAX: %.37e\n", result32);
}
hack32 = 0x00000001;
result32 = TOF(hack32);
if (FLT_MIN != result32) {
printf(" Testing for FLT_MIN: FAILED (%.104e)!\n", result32);
retval = 1;
} else {
printf(" Testing for FLT_MIN: %.104e\n", result32);
}
hack32 = 0x80000001;
result32 = TOF(hack32);
if (-FLT_MIN != result32) {
printf(" Testing for -FLT_MIN: FAILED (%.104e)!\n", result32);
retval = 1;
} else {
printf(" Testing for -FLT_MIN: %e.104\n", result32);
}
#if 0
hack32 = 0x7f800001;
result32 = TOF(hack32);
printf(" Testing for NaN: %f\n", result32);
#endif
#undef TOF
return retval;
}
int
test_64(void)
{
uint64_t hack64;
double result64;
int retval = 0;
if (8 != sizeof(double)) {
puts("sizeof double != 8, can not test");
return 1;
}
/*
* 1 bit sign 11 bit exponent 52 bit mantissa
*/
puts("DOUBLE:");
#define TOD(x) (*(double *)&(x))
hack64 = 0x7ff0000000000000;
result64 = TOD(hack64);
printf(" Testing for inf: %f\n", result64);
#if 0
/* XXX: how is the damn name of this... */
if (result64 != inf)
retval = 1;
#endif
hack64 = 0xfff0000000000000;
result64 = TOD(hack64);
printf(" Testing for -inf: %lf\n", result64);
hack64 = 0x7fefffffffffffff;
result64 = TOD(hack64);
if (DBL_MAX != result64) {
printf(" Testing for DBL_MAX: FAILED (%.308le)!\n", result64);
retval = 1;
} else {
printf(" Testing for DBL_MAX: %.308le\n", result64);
}
hack64 = 0xffefffffffffffff;
result64 = TOD(hack64);
if (-DBL_MAX != result64) {
printf(" Testing for -DBL_MAX: FAILED (%.308le)!\n", result64);
retval = 1;
} else {
printf(" Testing for -DBL_MAX: %.308le\n", result64);
}
hack64 = 0x0000000000000001;
result64 = TOD(hack64);
if (DBL_MIN != result64) {
printf(" Testing for DBL_MIN: FAILED (%.750le)!\n", result64);
retval = 1;
} else {
printf(" Testing for DBL_MIN: %.750le\n", result64);
}
hack64 = 0x8000000000000001;
result64 = TOD(hack64);
if (-DBL_MIN != result64) {
printf(" Testing for -DBL_MIN: FAILED (%.750le)!\n", result64);
retval = 1;
} else {
printf(" Testing for -DBL_MIN: %.750le\n", result64);
}
#if 0
hack64 = 0x7ff0000000000001;
result64 = TOD(hack64);
printf(" Testing for NaN: %lf\n", result64);
#endif
#undef TOD
return retval;
}
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20030330175646.281097ad.Alexander>
