1*f14fb602SLionel Sambuc /****************************************************************
2*f14fb602SLionel Sambuc
3*f14fb602SLionel Sambuc The author of this software is David M. Gay.
4*f14fb602SLionel Sambuc
5*f14fb602SLionel Sambuc Copyright (C) 1998 by Lucent Technologies
6*f14fb602SLionel Sambuc All Rights Reserved
7*f14fb602SLionel Sambuc
8*f14fb602SLionel Sambuc Permission to use, copy, modify, and distribute this software and
9*f14fb602SLionel Sambuc its documentation for any purpose and without fee is hereby
10*f14fb602SLionel Sambuc granted, provided that the above copyright notice appear in all
11*f14fb602SLionel Sambuc copies and that both that the copyright notice and this
12*f14fb602SLionel Sambuc permission notice and warranty disclaimer appear in supporting
13*f14fb602SLionel Sambuc documentation, and that the name of Lucent or any of its entities
14*f14fb602SLionel Sambuc not be used in advertising or publicity pertaining to
15*f14fb602SLionel Sambuc distribution of the software without specific, written prior
16*f14fb602SLionel Sambuc permission.
17*f14fb602SLionel Sambuc
18*f14fb602SLionel Sambuc LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
19*f14fb602SLionel Sambuc INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
20*f14fb602SLionel Sambuc IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
21*f14fb602SLionel Sambuc SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
22*f14fb602SLionel Sambuc WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
23*f14fb602SLionel Sambuc IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
24*f14fb602SLionel Sambuc ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
25*f14fb602SLionel Sambuc THIS SOFTWARE.
26*f14fb602SLionel Sambuc
27*f14fb602SLionel Sambuc ****************************************************************/
28*f14fb602SLionel Sambuc
29*f14fb602SLionel Sambuc /* Please send bug reports to David M. Gay (dmg at acm dot org,
30*f14fb602SLionel Sambuc * with " at " changed at "@" and " dot " changed to "."). */
31*f14fb602SLionel Sambuc
32*f14fb602SLionel Sambuc #include <stdio.h>
33*f14fb602SLionel Sambuc #include <stdlib.h>
34*f14fb602SLionel Sambuc
35*f14fb602SLionel Sambuc static char *dir[4] = { "toward zero", "nearest", "toward +Infinity",
36*f14fb602SLionel Sambuc "toward -Infinity" };
37*f14fb602SLionel Sambuc
38*f14fb602SLionel Sambuc #ifdef Honor_FLT_ROUNDS
39*f14fb602SLionel Sambuc #include <fenv.h>
40*f14fb602SLionel Sambuc static int fe_conv[4] = {FE_TOWARDZERO, FE_TONEAREST, FE_UPWARD, FE_DOWNWARD };
41*f14fb602SLionel Sambuc #endif
42*f14fb602SLionel Sambuc
43*f14fb602SLionel Sambuc int
44*f14fb602SLionel Sambuc #ifdef KR_headers
getround(r,s)45*f14fb602SLionel Sambuc getround(r, s) int r; char *s;
46*f14fb602SLionel Sambuc #else
47*f14fb602SLionel Sambuc getround(int r, char *s)
48*f14fb602SLionel Sambuc #endif
49*f14fb602SLionel Sambuc {
50*f14fb602SLionel Sambuc int i;
51*f14fb602SLionel Sambuc
52*f14fb602SLionel Sambuc while(*++s <= ' ') {
53*f14fb602SLionel Sambuc if (!*s) {
54*f14fb602SLionel Sambuc printf("Current round mode for strtor... is %d (%s).\n",
55*f14fb602SLionel Sambuc r, dir[r]);
56*f14fb602SLionel Sambuc return r;
57*f14fb602SLionel Sambuc }
58*f14fb602SLionel Sambuc }
59*f14fb602SLionel Sambuc i = atoi(s);
60*f14fb602SLionel Sambuc if (i >= 0 && i < 4) {
61*f14fb602SLionel Sambuc printf("Rounding mode for strtor... ");
62*f14fb602SLionel Sambuc if (i == r)
63*f14fb602SLionel Sambuc printf("was and is %d (%s)\n", i, dir[i]);
64*f14fb602SLionel Sambuc else
65*f14fb602SLionel Sambuc printf("changed from %d (%s) to %d (%s)\n",
66*f14fb602SLionel Sambuc r, dir[r], i, dir[i]);
67*f14fb602SLionel Sambuc #ifdef Honor_FLT_ROUNDS
68*f14fb602SLionel Sambuc fesetround(fe_conv[i]);
69*f14fb602SLionel Sambuc #endif
70*f14fb602SLionel Sambuc return i;
71*f14fb602SLionel Sambuc }
72*f14fb602SLionel Sambuc printf("Bad rounding direction %d: choose among\n", i);
73*f14fb602SLionel Sambuc for(i = 0; i < 4; i++)
74*f14fb602SLionel Sambuc printf("\t%d (%s)\n", i, dir[i]);
75*f14fb602SLionel Sambuc printf("Leaving rounding mode for strtor... at %d (%s)\n", r, dir[r]);
76*f14fb602SLionel Sambuc return r;
77*f14fb602SLionel Sambuc }
78*f14fb602SLionel Sambuc
79*f14fb602SLionel Sambuc #ifdef USE_MY_LOCALE
80*f14fb602SLionel Sambuc #include <locale.h>
81*f14fb602SLionel Sambuc
82*f14fb602SLionel Sambuc struct lconv *
localeconv(void)83*f14fb602SLionel Sambuc localeconv(void)
84*f14fb602SLionel Sambuc {
85*f14fb602SLionel Sambuc static struct lconv mylocale;
86*f14fb602SLionel Sambuc mylocale.decimal_point = "<Pt>";
87*f14fb602SLionel Sambuc return &mylocale;
88*f14fb602SLionel Sambuc }
89*f14fb602SLionel Sambuc #endif
90*f14fb602SLionel Sambuc
91