decNumber.c (3dd359c2d34c6abf385d58da863f337b39702585) | decNumber.c (67cc32ebfd8c0ee3fcdb26780a8991baf5eb1d45) |
---|---|
1/* Decimal number arithmetic module for the decNumber C Library. 2 Copyright (C) 2005, 2007 Free Software Foundation, Inc. 3 Contributed by IBM Corporation. Author Mike Cowlishaw. 4 5 This file is part of GCC. 6 7 GCC is free software; you can redistribute it and/or modify it under 8 the terms of the GNU General Public License as published by the Free --- 2224 unchanged lines hidden (view full) --- 2233 2234 else { /* carry on with integer */ 2235 decNumberZero(dac); /* acc=1 */ 2236 *dac->lsu=1; /* .. */ 2237 2238 /* if a negative power the constant 1 is needed, and if not subset */ 2239 /* invert the lhs now rather than inverting the result later */ 2240 if (decNumberIsNegative(rhs)) { /* was a **-n [hence digits>0] */ | 1/* Decimal number arithmetic module for the decNumber C Library. 2 Copyright (C) 2005, 2007 Free Software Foundation, Inc. 3 Contributed by IBM Corporation. Author Mike Cowlishaw. 4 5 This file is part of GCC. 6 7 GCC is free software; you can redistribute it and/or modify it under 8 the terms of the GNU General Public License as published by the Free --- 2224 unchanged lines hidden (view full) --- 2233 2234 else { /* carry on with integer */ 2235 decNumberZero(dac); /* acc=1 */ 2236 *dac->lsu=1; /* .. */ 2237 2238 /* if a negative power the constant 1 is needed, and if not subset */ 2239 /* invert the lhs now rather than inverting the result later */ 2240 if (decNumberIsNegative(rhs)) { /* was a **-n [hence digits>0] */ |
2241 decNumber *inv=invbuff; /* asssume use fixed buffer */ | 2241 decNumber *inv=invbuff; /* assume use fixed buffer */ |
2242 decNumberCopy(&dnOne, dac); /* dnOne=1; [needed now or later] */ 2243 #if DECSUBSET 2244 if (set->extended) { /* need to calculate 1/lhs */ 2245 #endif 2246 /* divide lhs into 1, putting result in dac [dac=1/dac] */ 2247 decDivideOp(dac, &dnOne, lhs, &aset, DIVIDE, &status); 2248 /* now locate or allocate space for the inverted lhs */ 2249 if (needbytes>sizeof(invbuff)) { --- 1594 unchanged lines hidden (view full) --- 3844/* */ 3845/* Misalignment is handled as follows: */ 3846/* Apad: (AExp>BExp) Swap operands and proceed as for BExp>AExp. */ 3847/* BPad: Apply the padding by a combination of shifting (whole */ 3848/* units) and multiplication (part units). */ 3849/* */ 3850/* Addition, especially x=x+1, is speed-critical. */ 3851/* The static buffer is larger than might be expected to allow for */ | 2242 decNumberCopy(&dnOne, dac); /* dnOne=1; [needed now or later] */ 2243 #if DECSUBSET 2244 if (set->extended) { /* need to calculate 1/lhs */ 2245 #endif 2246 /* divide lhs into 1, putting result in dac [dac=1/dac] */ 2247 decDivideOp(dac, &dnOne, lhs, &aset, DIVIDE, &status); 2248 /* now locate or allocate space for the inverted lhs */ 2249 if (needbytes>sizeof(invbuff)) { --- 1594 unchanged lines hidden (view full) --- 3844/* */ 3845/* Misalignment is handled as follows: */ 3846/* Apad: (AExp>BExp) Swap operands and proceed as for BExp>AExp. */ 3847/* BPad: Apply the padding by a combination of shifting (whole */ 3848/* units) and multiplication (part units). */ 3849/* */ 3850/* Addition, especially x=x+1, is speed-critical. */ 3851/* The static buffer is larger than might be expected to allow for */ |
3852/* calls from higher-level funtions (notable exp). */ | 3852/* calls from higher-level functions (notably exp). */ |
3853/* ------------------------------------------------------------------ */ 3854static decNumber * decAddOp(decNumber *res, const decNumber *lhs, 3855 const decNumber *rhs, decContext *set, 3856 uByte negate, uInt *status) { 3857 #if DECSUBSET 3858 decNumber *alloclhs=NULL; /* non-NULL if rounded lhs allocated */ 3859 decNumber *allocrhs=NULL; /* .., rhs */ 3860 #endif --- 397 unchanged lines hidden (view full) --- 4258/* Return (Result is defined by Var1) */ 4259/* */ 4260/* ------------------------------------------------------------------ */ 4261/* Two working buffers are needed during the division; one (digits+ */ 4262/* 1) to accumulate the result, and the other (up to 2*digits+1) for */ 4263/* long subtractions. These are acc and var1 respectively. */ 4264/* var1 is a copy of the lhs coefficient, var2 is the rhs coefficient.*/ 4265/* The static buffers may be larger than might be expected to allow */ | 3853/* ------------------------------------------------------------------ */ 3854static decNumber * decAddOp(decNumber *res, const decNumber *lhs, 3855 const decNumber *rhs, decContext *set, 3856 uByte negate, uInt *status) { 3857 #if DECSUBSET 3858 decNumber *alloclhs=NULL; /* non-NULL if rounded lhs allocated */ 3859 decNumber *allocrhs=NULL; /* .., rhs */ 3860 #endif --- 397 unchanged lines hidden (view full) --- 4258/* Return (Result is defined by Var1) */ 4259/* */ 4260/* ------------------------------------------------------------------ */ 4261/* Two working buffers are needed during the division; one (digits+ */ 4262/* 1) to accumulate the result, and the other (up to 2*digits+1) for */ 4263/* long subtractions. These are acc and var1 respectively. */ 4264/* var1 is a copy of the lhs coefficient, var2 is the rhs coefficient.*/ 4265/* The static buffers may be larger than might be expected to allow */ |
4266/* for calls from higher-level funtions (notable exp). */ | 4266/* for calls from higher-level functions (notably exp). */ |
4267/* ------------------------------------------------------------------ */ 4268static decNumber * decDivideOp(decNumber *res, 4269 const decNumber *lhs, const decNumber *rhs, 4270 decContext *set, Flag op, uInt *status) { 4271 #if DECSUBSET 4272 decNumber *alloclhs=NULL; /* non-NULL if rounded lhs allocated */ 4273 decNumber *allocrhs=NULL; /* .., rhs */ 4274 #endif --- 974 unchanged lines hidden (view full) --- 5249/* */ 5250/* 1. This is separated out as decExpOp so it can be called from */ 5251/* other Mathematical functions (notably Ln) with a wider range */ 5252/* than normal. In particular, it can handle the slightly wider */ 5253/* (double) range needed by Ln (which has to be able to calculate */ 5254/* exp(-x) where x can be the tiniest number (Ntiny). */ 5255/* */ 5256/* 2. Normalizing x to be <=0.1 (instead of <=1) reduces loop */ | 4267/* ------------------------------------------------------------------ */ 4268static decNumber * decDivideOp(decNumber *res, 4269 const decNumber *lhs, const decNumber *rhs, 4270 decContext *set, Flag op, uInt *status) { 4271 #if DECSUBSET 4272 decNumber *alloclhs=NULL; /* non-NULL if rounded lhs allocated */ 4273 decNumber *allocrhs=NULL; /* .., rhs */ 4274 #endif --- 974 unchanged lines hidden (view full) --- 5249/* */ 5250/* 1. This is separated out as decExpOp so it can be called from */ 5251/* other Mathematical functions (notably Ln) with a wider range */ 5252/* than normal. In particular, it can handle the slightly wider */ 5253/* (double) range needed by Ln (which has to be able to calculate */ 5254/* exp(-x) where x can be the tiniest number (Ntiny). */ 5255/* */ 5256/* 2. Normalizing x to be <=0.1 (instead of <=1) reduces loop */ |
5257/* iterations by appoximately a third with additional (although */ | 5257/* iterations by approximately a third with additional (although */ |
5258/* diminishing) returns as the range is reduced to even smaller */ 5259/* fractions. However, h (the power of 10 used to correct the */ 5260/* result at the end, see below) must be kept <=8 as otherwise */ 5261/* the final result cannot be computed. Hence the leverage is a */ 5262/* sliding value (8-h), where potentially the range is reduced */ 5263/* more for smaller values. */ 5264/* */ 5265/* The leverage that can be applied in this way is severely */ --- 2930 unchanged lines hidden --- | 5258/* diminishing) returns as the range is reduced to even smaller */ 5259/* fractions. However, h (the power of 10 used to correct the */ 5260/* result at the end, see below) must be kept <=8 as otherwise */ 5261/* the final result cannot be computed. Hence the leverage is a */ 5262/* sliding value (8-h), where potentially the range is reduced */ 5263/* more for smaller values. */ 5264/* */ 5265/* The leverage that can be applied in this way is severely */ --- 2930 unchanged lines hidden --- |