------------------------------------------------------------------ */ decContextDefault -- initialize a context structure */ / context is the structure to be initialized */ kind selects the required set of default values, one of: */ DEC_INIT_BASE -- select ANSI X3-274 defaults */ DEC_INIT_DECIMAL32 -- select IEEE 754 defaults, 32-bit
| 70 | /* returns a context structure with the appropriate initial values. */ |
| 71 | /* ------------------------------------------------------------------ */ |
| 72 | decContext * decContextDefault(decContext *context, Int kind) { |
| 73 | // set defaults... |
| 74 | context->digits=9; // 9 digits |
| 75 | context->emax=DEC_MAX_EMAX; // 9-digit exponents |
| 76 | context->emin=DEC_MIN_EMIN; // .. balanced |
| 77 | context->round=DEC_ROUND_HALF_UP; // 0.5 rises |
| 78 | context->traps=DEC_Errors; // all but informational |
| 79 | context->status=0; // cleared |
| 80 | context->clamp=0; // no clamping |
| 81 | #if DECSUBSET |
| 82 | context->extended=0; // cleared |
| 83 | #endif |
| 84 | switch (kind) { |
| 85 | case DEC_INIT_BASE: |
| 86 | // [use defaults] |
| 87 | break; |
| 88 | case DEC_INIT_DECIMAL32: |
| 89 | context->digits=7; // digits |
| 90 | context->emax=96; // Emax |
| 91 | context->emin=-95; // Emin |
| 92 | context->round=DEC_ROUND_HALF_EVEN; // 0.5 to nearest even |
| 93 | context->traps=0; // no traps set |
| 94 | context->clamp=1; // clamp exponents |
| 95 | #if DECSUBSET |
| 96 | context->extended=1; // set |
| 97 | #endif |
| 98 | break; |
| 99 | case DEC_INIT_DECIMAL64: |
| 100 | context->digits=16; // digits |
| 101 | context->emax=384; // Emax |
| 102 | context->emin=-383; // Emin |
| 103 | context->round=DEC_ROUND_HALF_EVEN; // 0.5 to nearest even |
| 104 | context->traps=0; // no traps set |
| 105 | context->clamp=1; // clamp exponents |
| 106 | #if DECSUBSET |
| 107 | context->extended=1; // set |
| 108 | #endif |
| 109 | break; |
| 110 | case DEC_INIT_DECIMAL128: |
| 111 | context->digits=34; // digits |
| 112 | context->emax=6144; // Emax |
| 113 | context->emin=-6143; // Emin |
| 114 | context->round=DEC_ROUND_HALF_EVEN; // 0.5 to nearest even |
| 115 | context->traps=0; // no traps set |
| 116 | context->clamp=1; // clamp exponents |
| 117 | #if DECSUBSET |
| 118 | context->extended=1; // set |
| 119 | #endif |
| 120 | break; |
| 121 | |
| 122 | default: // invalid Kind |
| 123 | // use defaults, and .. |
| 124 | decContextSetStatus(context, DEC_Invalid_operation); // trap |
| 125 | } |
| 126 | |
| 127 | return context;} // decContextDefault |
| 128 | |
| 129 | /* ------------------------------------------------------------------ */ |
no test coverage detected