1 /* ------------------------------------------------------------------ */ 2 /* Decimal 64-bit format module header */ 3 /* ------------------------------------------------------------------ */ 4 /* Copyright (c) IBM Corporation, 2000, 2005. All rights reserved. */ 5 /* */ 6 /* This software is made available under the terms of the */ 7 /* ICU License -- ICU 1.8.1 and later. */ 8 /* */ 9 /* The description and User's Guide ("The decNumber C Library") for */ 10 /* this software is called decNumber.pdf. This document is */ 11 /* available, together with arithmetic and format specifications, */ 12 /* testcases, and Web links, on the General Decimal Arithmetic page. */ 13 /* */ 14 /* Please send comments, suggestions, and corrections to the author: */ 15 /* mfc@uk.ibm.com */ 16 /* Mike Cowlishaw, IBM Fellow */ 17 /* IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK */ 18 /* ------------------------------------------------------------------ */ 19 20 #if !defined(DECIMAL64) 21 #define DECIMAL64 22 #define DEC64NAME "decimal64" /* Short name */ 23 #define DEC64FULLNAME "Decimal 64-bit Number" /* Verbose name */ 24 #define DEC64AUTHOR "Mike Cowlishaw" /* Who to blame */ 25 26 27 /* parameters for decimal64s */ 28 #define DECIMAL64_Bytes 8 /* length */ 29 #define DECIMAL64_Pmax 16 /* maximum precision (digits) */ 30 #define DECIMAL64_Emax 384 /* maximum adjusted exponent */ 31 #define DECIMAL64_Emin -383 /* minimum adjusted exponent */ 32 #define DECIMAL64_Bias 398 /* bias for the exponent */ 33 #define DECIMAL64_String 24 /* maximum string length, +1 */ 34 #define DECIMAL64_EconL 8 /* exp. continuation length */ 35 /* highest biased exponent (Elimit-1) */ 36 #define DECIMAL64_Ehigh (DECIMAL64_Emax+DECIMAL64_Bias-DECIMAL64_Pmax+1) 37 38 /* check enough digits, if pre-defined */ 39 #if defined(DECNUMDIGITS) 40 #if (DECNUMDIGITS<DECIMAL64_Pmax) 41 #error decimal64.h needs pre-defined DECNUMDIGITS>=16 for safe use 42 #endif 43 #endif 44 45 46 #ifndef DECNUMDIGITS 47 #define DECNUMDIGITS DECIMAL64_Pmax /* size if not already defined*/ 48 #endif 49 #ifndef DECNUMBER 50 #include "decNumber.h" /* context and number library */ 51 #endif 52 53 /* Decimal 64-bit type, accessible by bytes */ 54 typedef struct { 55 uint8_t bytes[DECIMAL64_Bytes]; /* decimal64: 1, 5, 8, 50 bits*/ 56 } decimal64; 57 58 /* special values [top byte excluding sign bit; last two bits are */ 59 /* don't-care for Infinity on input, last bit don't-care for NaN] */ 60 #if !defined(DECIMAL_NaN) 61 #define DECIMAL_NaN 0x7c /* 0 11111 00 NaN */ 62 #define DECIMAL_sNaN 0x7e /* 0 11111 10 sNaN */ 63 #define DECIMAL_Inf 0x78 /* 0 11110 00 Infinity */ 64 #endif 65 66 /* ---------------------------------------------------------------- */ 67 /* Routines */ 68 /* ---------------------------------------------------------------- */ 69 /* String conversions */ 70 decimal64 * decimal64FromString(decimal64 *, const char *, decContext *); 71 char * decimal64ToString(const decimal64 *, char *); 72 char * decimal64ToEngString(const decimal64 *, char *); 73 74 /* decNumber conversions */ 75 decimal64 * decimal64FromNumber(decimal64 *, const decNumber *, 76 decContext *); 77 decNumber * decimal64ToNumber(const decimal64 *, decNumber *); 78 79 /* Format-dependent utilities */ 80 uint32_t decimal64IsCanonical(const decimal64 *); 81 decimal64 * decimal64Canonical(decimal64 *, const decimal64 *); 82 83 #endif 84