X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=lib%2Fprintf-frexp.c;fp=lib%2Fprintf-frexp.c;h=1a53846851e973b662d9eae050ecfaf33575fb9c;hb=a2016c1de6e4884f6c8ed5cc498f3bf821c25ca4;hp=da5c9c3a458084e9d09e5cde553cba77968d7c3e;hpb=c7e61475680fa226bd9b8bdd469cd66914e630f5;p=debian%2Fgzip diff --git a/lib/printf-frexp.c b/lib/printf-frexp.c index da5c9c3..1a53846 100644 --- a/lib/printf-frexp.c +++ b/lib/printf-frexp.c @@ -1,5 +1,5 @@ /* Split a double into fraction and mantissa, for hexadecimal printf. - Copyright (C) 2007 Free Software Foundation, Inc. + Copyright (C) 2007, 2009, 2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -92,76 +92,76 @@ FUNC (DOUBLE x, int *expptr) exponent = 0; if (x >= L_(1.0)) { - /* A nonnegative exponent. */ - { - DOUBLE pow2_i; /* = pow2[i] */ - DOUBLE powh_i; /* = powh[i] */ - - /* Invariants: pow2_i = 2^2^i, powh_i = 2^-2^i, - x * 2^exponent = argument, x >= 1.0. */ - for (i = 0, pow2_i = L_(2.0), powh_i = L_(0.5); - ; - i++, pow2_i = pow2_i * pow2_i, powh_i = powh_i * powh_i) - { - if (x >= pow2_i) - { - exponent += (1 << i); - x *= powh_i; - } - else - break; - - pow2[i] = pow2_i; - powh[i] = powh_i; - } - } - /* Here 1.0 <= x < 2^2^i. */ + /* A nonnegative exponent. */ + { + DOUBLE pow2_i; /* = pow2[i] */ + DOUBLE powh_i; /* = powh[i] */ + + /* Invariants: pow2_i = 2^2^i, powh_i = 2^-2^i, + x * 2^exponent = argument, x >= 1.0. */ + for (i = 0, pow2_i = L_(2.0), powh_i = L_(0.5); + ; + i++, pow2_i = pow2_i * pow2_i, powh_i = powh_i * powh_i) + { + if (x >= pow2_i) + { + exponent += (1 << i); + x *= powh_i; + } + else + break; + + pow2[i] = pow2_i; + powh[i] = powh_i; + } + } + /* Here 1.0 <= x < 2^2^i. */ } else { - /* A negative exponent. */ - { - DOUBLE pow2_i; /* = pow2[i] */ - DOUBLE powh_i; /* = powh[i] */ - - /* Invariants: pow2_i = 2^2^i, powh_i = 2^-2^i, - x * 2^exponent = argument, x < 1.0, exponent >= MIN_EXP - 1. */ - for (i = 0, pow2_i = L_(2.0), powh_i = L_(0.5); - ; - i++, pow2_i = pow2_i * pow2_i, powh_i = powh_i * powh_i) - { - if (exponent - (1 << i) < MIN_EXP - 1) - break; - - exponent -= (1 << i); - x *= pow2_i; - if (x >= L_(1.0)) - break; - - pow2[i] = pow2_i; - powh[i] = powh_i; - } - } - /* Here either x < 1.0 and exponent - 2^i < MIN_EXP - 1 <= exponent, - or 1.0 <= x < 2^2^i and exponent >= MIN_EXP - 1. */ - - if (x < L_(1.0)) - /* Invariants: x * 2^exponent = argument, x < 1.0 and - exponent - 2^i < MIN_EXP - 1 <= exponent. */ - while (i > 0) - { - i--; - if (exponent - (1 << i) >= MIN_EXP - 1) - { - exponent -= (1 << i); - x *= pow2[i]; - if (x >= L_(1.0)) - break; - } - } - - /* Here either x < 1.0 and exponent = MIN_EXP - 1, - or 1.0 <= x < 2^2^i and exponent >= MIN_EXP - 1. */ + /* A negative exponent. */ + { + DOUBLE pow2_i; /* = pow2[i] */ + DOUBLE powh_i; /* = powh[i] */ + + /* Invariants: pow2_i = 2^2^i, powh_i = 2^-2^i, + x * 2^exponent = argument, x < 1.0, exponent >= MIN_EXP - 1. */ + for (i = 0, pow2_i = L_(2.0), powh_i = L_(0.5); + ; + i++, pow2_i = pow2_i * pow2_i, powh_i = powh_i * powh_i) + { + if (exponent - (1 << i) < MIN_EXP - 1) + break; + + exponent -= (1 << i); + x *= pow2_i; + if (x >= L_(1.0)) + break; + + pow2[i] = pow2_i; + powh[i] = powh_i; + } + } + /* Here either x < 1.0 and exponent - 2^i < MIN_EXP - 1 <= exponent, + or 1.0 <= x < 2^2^i and exponent >= MIN_EXP - 1. */ + + if (x < L_(1.0)) + /* Invariants: x * 2^exponent = argument, x < 1.0 and + exponent - 2^i < MIN_EXP - 1 <= exponent. */ + while (i > 0) + { + i--; + if (exponent - (1 << i) >= MIN_EXP - 1) + { + exponent -= (1 << i); + x *= pow2[i]; + if (x >= L_(1.0)) + break; + } + } + + /* Here either x < 1.0 and exponent = MIN_EXP - 1, + or 1.0 <= x < 2^2^i and exponent >= MIN_EXP - 1. */ } /* Invariants: x * 2^exponent = argument, and @@ -169,12 +169,12 @@ FUNC (DOUBLE x, int *expptr) or 1.0 <= x < 2^2^i and exponent >= MIN_EXP - 1. */ while (i > 0) { - i--; - if (x >= pow2[i]) - { - exponent += (1 << i); - x *= powh[i]; - } + i--; + if (x >= pow2[i]) + { + exponent += (1 << i); + x *= powh[i]; + } } /* Here either x < 1.0 and exponent = MIN_EXP - 1, or 1.0 <= x < 2.0 and exponent >= MIN_EXP - 1. */