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