Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(427)

Side by Side Diff: base/third_party/dmg_fp/dtoa.cc

Issue 590413006: Fix more MSVC warnings, this time mostly about possible value truncation (fixed (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | base/third_party/dmg_fp/g_fmt.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /**************************************************************** 1 /****************************************************************
2 * 2 *
3 * The author of this software is David M. Gay. 3 * The author of this software is David M. Gay.
4 * 4 *
5 * Copyright (c) 1991, 2000, 2001 by Lucent Technologies. 5 * Copyright (c) 1991, 2000, 2001 by Lucent Technologies.
6 * 6 *
7 * Permission to use, copy, modify, and distribute this software for any 7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose without fee is hereby granted, provided that this entire notice 8 * purpose without fee is hereby granted, provided that this entire notice
9 * is included in all copies of any software which is or includes a copy 9 * is included in all copies of any software which is or includes a copy
10 * or modification of this software and in all copies of the supporting 10 * or modification of this software and in all copies of the supporting
(...skipping 634 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 #endif 645 #endif
646 } 646 }
647 while(++i < wds); 647 while(++i < wds);
648 if (carry) { 648 if (carry) {
649 if (wds >= b->maxwds) { 649 if (wds >= b->maxwds) {
650 b1 = Balloc(b->k+1); 650 b1 = Balloc(b->k+1);
651 Bcopy(b1, b); 651 Bcopy(b1, b);
652 Bfree(b); 652 Bfree(b);
653 b = b1; 653 b = b1;
654 } 654 }
655 » » b->x[wds++] = carry; 655 » » b->x[wds++] = (ULong)carry;
656 b->wds = wds; 656 b->wds = wds;
657 } 657 }
658 return b; 658 return b;
659 } 659 }
660 660
661 static Bigint * 661 static Bigint *
662 s2b 662 s2b
663 #ifdef KR_headers 663 #ifdef KR_headers
664 (s, nd0, nd, y9, dplen) CONST char *s; int nd0, nd, dplen; ULong y9; 664 (s, nd0, nd, y9, dplen) CONST char *s; int nd0, nd, dplen; ULong y9;
665 #else 665 #else
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
840 if (y) { 840 if (y) {
841 x = xa; 841 x = xa;
842 xc = xc0; 842 xc = xc0;
843 carry = 0; 843 carry = 0;
844 do { 844 do {
845 z = *x++ * (ULLong)y + *xc + carry; 845 z = *x++ * (ULLong)y + *xc + carry;
846 carry = z >> 32; 846 carry = z >> 32;
847 *xc++ = z & FFFFFFFF; 847 *xc++ = z & FFFFFFFF;
848 } 848 }
849 while(x < xae); 849 while(x < xae);
850 » » » *xc = carry; 850 » » » *xc = (ULong)carry;
851 } 851 }
852 } 852 }
853 #else 853 #else
854 #ifdef Pack_32 854 #ifdef Pack_32
855 for(; xb < xbe; xb++, xc0++) { 855 for(; xb < xbe; xb++, xc0++) {
856 if (y = *xb & 0xffff) { 856 if (y = *xb & 0xffff) {
857 x = xa; 857 x = xa;
858 xc = xc0; 858 xc = xc0;
859 carry = 0; 859 carry = 0;
860 do { 860 do {
(...skipping 643 matching lines...) Expand 10 before | Expand all | Expand 10 after
1504 1504
1505 static void 1505 static void
1506 #ifdef KR_headers 1506 #ifdef KR_headers
1507 htinit(h, s, inc) unsigned char *h; unsigned char *s; int inc; 1507 htinit(h, s, inc) unsigned char *h; unsigned char *s; int inc;
1508 #else 1508 #else
1509 htinit(unsigned char *h, unsigned char *s, int inc) 1509 htinit(unsigned char *h, unsigned char *s, int inc)
1510 #endif 1510 #endif
1511 { 1511 {
1512 int i, j; 1512 int i, j;
1513 for(i = 0; (j = s[i]) !=0; i++) 1513 for(i = 0; (j = s[i]) !=0; i++)
1514 » » h[j] = i + inc; 1514 » » h[j] = (unsigned char)(i + inc);
1515 } 1515 }
1516 1516
1517 static void 1517 static void
1518 #ifdef KR_headers 1518 #ifdef KR_headers
1519 hexdig_init() 1519 hexdig_init()
1520 #else 1520 #else
1521 hexdig_init(void) 1521 hexdig_init(void)
1522 #endif 1522 #endif
1523 { 1523 {
1524 #define USC (unsigned char *) 1524 #define USC (unsigned char *)
(...skipping 1771 matching lines...) Expand 10 before | Expand all | Expand 10 after
3296 word1(&rv) = Big1; 3296 word1(&rv) = Big1;
3297 goto cont; 3297 goto cont;
3298 } 3298 }
3299 else 3299 else
3300 word0(&rv) += P*Exp_msk1; 3300 word0(&rv) += P*Exp_msk1;
3301 } 3301 }
3302 else { 3302 else {
3303 #ifdef Avoid_Underflow 3303 #ifdef Avoid_Underflow
3304 if (bc.scale && y <= 2*P*Exp_msk1) { 3304 if (bc.scale && y <= 2*P*Exp_msk1) {
3305 if (aadj <= 0x7fffffff) { 3305 if (aadj <= 0x7fffffff) {
3306 » » » » » if ((z = aadj) <= 0) 3306 » » » » » if ((z = (ULong)aadj) <= 0)
3307 z = 1; 3307 z = 1;
3308 aadj = z; 3308 aadj = z;
3309 aadj1 = bc.dsign ? aadj : -aadj; 3309 aadj1 = bc.dsign ? aadj : -aadj;
3310 } 3310 }
3311 dval(&aadj2) = aadj1; 3311 dval(&aadj2) = aadj1;
3312 word0(&aadj2) += (2*P+1)*Exp_msk1 - y; 3312 word0(&aadj2) += (2*P+1)*Exp_msk1 - y;
3313 aadj1 = dval(&aadj2); 3313 aadj1 = dval(&aadj2);
3314 } 3314 }
3315 adj.d = aadj1 * ulp(&rv); 3315 adj.d = aadj1 * ulp(&rv);
3316 dval(&rv) += adj.d; 3316 dval(&rv) += adj.d;
(...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after
3852 goto no_digits; 3852 goto no_digits;
3853 goto fast_failed; 3853 goto fast_failed;
3854 } 3854 }
3855 #ifndef No_leftright 3855 #ifndef No_leftright
3856 if (leftright) { 3856 if (leftright) {
3857 /* Use Steele & White method of only 3857 /* Use Steele & White method of only
3858 * generating digits needed. 3858 * generating digits needed.
3859 */ 3859 */
3860 dval(&eps) = 0.5/tens[ilim-1] - dval(&eps); 3860 dval(&eps) = 0.5/tens[ilim-1] - dval(&eps);
3861 for(i = 0;;) { 3861 for(i = 0;;) {
3862 » » » » L = dval(&u); 3862 » » » » L = (long)dval(&u);
3863 dval(&u) -= L; 3863 dval(&u) -= L;
3864 » » » » *s++ = '0' + (int)L; 3864 » » » » *s++ = '0' + (char)L;
3865 if (dval(&u) < dval(&eps)) 3865 if (dval(&u) < dval(&eps))
3866 goto ret1; 3866 goto ret1;
3867 if (1. - dval(&u) < dval(&eps)) 3867 if (1. - dval(&u) < dval(&eps))
3868 goto bump_up; 3868 goto bump_up;
3869 if (++i >= ilim) 3869 if (++i >= ilim)
3870 break; 3870 break;
3871 dval(&eps) *= 10.; 3871 dval(&eps) *= 10.;
3872 dval(&u) *= 10.; 3872 dval(&u) *= 10.;
3873 } 3873 }
3874 } 3874 }
3875 else { 3875 else {
3876 #endif 3876 #endif
3877 /* Generate ilim digits, then fix them up. */ 3877 /* Generate ilim digits, then fix them up. */
3878 dval(&eps) *= tens[ilim-1]; 3878 dval(&eps) *= tens[ilim-1];
3879 for(i = 1;; i++, dval(&u) *= 10.) { 3879 for(i = 1;; i++, dval(&u) *= 10.) {
3880 L = (Long)(dval(&u)); 3880 L = (Long)(dval(&u));
3881 if (!(dval(&u) -= L)) 3881 if (!(dval(&u) -= L))
3882 ilim = i; 3882 ilim = i;
3883 » » » » *s++ = '0' + (int)L; 3883 » » » » *s++ = '0' + (char)L;
3884 if (i == ilim) { 3884 if (i == ilim) {
3885 if (dval(&u) > 0.5 + dval(&eps)) 3885 if (dval(&u) > 0.5 + dval(&eps))
3886 goto bump_up; 3886 goto bump_up;
3887 else if (dval(&u) < 0.5 - dval(&eps)) { 3887 else if (dval(&u) < 0.5 - dval(&eps)) {
3888 while(*--s == '0') {} 3888 while(*--s == '0') {}
3889 s++; 3889 s++;
3890 goto ret1; 3890 goto ret1;
3891 } 3891 }
3892 break; 3892 break;
3893 } 3893 }
(...skipping 22 matching lines...) Expand all
3916 for(i = 1; i <= k + 1; i++, dval(&u) *= 10.) { 3916 for(i = 1; i <= k + 1; i++, dval(&u) *= 10.) {
3917 L = (Long)(dval(&u) / ds); 3917 L = (Long)(dval(&u) / ds);
3918 dval(&u) -= L*ds; 3918 dval(&u) -= L*ds;
3919 #ifdef Check_FLT_ROUNDS 3919 #ifdef Check_FLT_ROUNDS
3920 /* If FLT_ROUNDS == 2, L will usually be high by 1 */ 3920 /* If FLT_ROUNDS == 2, L will usually be high by 1 */
3921 if (dval(&u) < 0) { 3921 if (dval(&u) < 0) {
3922 L--; 3922 L--;
3923 dval(&u) += ds; 3923 dval(&u) += ds;
3924 } 3924 }
3925 #endif 3925 #endif
3926 » » » *s++ = '0' + (int)L; 3926 » » » *s++ = '0' + (char)L;
3927 if (!dval(&u)) { 3927 if (!dval(&u)) {
3928 #ifdef SET_INEXACT 3928 #ifdef SET_INEXACT
3929 inexact = 0; 3929 inexact = 0;
3930 #endif 3930 #endif
3931 break; 3931 break;
3932 } 3932 }
3933 if (i == ilim) { 3933 if (i == ilim) {
3934 #ifdef Honor_FLT_ROUNDS 3934 #ifdef Honor_FLT_ROUNDS
3935 if (mode > 1) 3935 if (mode > 1)
3936 switch(Rounding) { 3936 switch(Rounding) {
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
4094 #endif 4094 #endif
4095 ) { 4095 ) {
4096 if (dig == '9') 4096 if (dig == '9')
4097 goto round_9_up; 4097 goto round_9_up;
4098 if (j > 0) 4098 if (j > 0)
4099 dig++; 4099 dig++;
4100 #ifdef SET_INEXACT 4100 #ifdef SET_INEXACT
4101 else if (!b->x[0] && b->wds <= 1) 4101 else if (!b->x[0] && b->wds <= 1)
4102 inexact = 0; 4102 inexact = 0;
4103 #endif 4103 #endif
4104 » » » » *s++ = dig; 4104 » » » » *s++ = (char)dig;
4105 goto ret; 4105 goto ret;
4106 } 4106 }
4107 #endif 4107 #endif
4108 if (j < 0 || (j == 0 && mode != 1 4108 if (j < 0 || (j == 0 && mode != 1
4109 #ifndef ROUND_BIASED 4109 #ifndef ROUND_BIASED
4110 && !(word1(&u) & 1) 4110 && !(word1(&u) & 1)
4111 #endif 4111 #endif
4112 )) { 4112 )) {
4113 if (!b->x[0] && b->wds <= 1) { 4113 if (!b->x[0] && b->wds <= 1) {
4114 #ifdef SET_INEXACT 4114 #ifdef SET_INEXACT
4115 inexact = 0; 4115 inexact = 0;
4116 #endif 4116 #endif
4117 goto accept_dig; 4117 goto accept_dig;
4118 } 4118 }
4119 #ifdef Honor_FLT_ROUNDS 4119 #ifdef Honor_FLT_ROUNDS
4120 if (mode > 1) 4120 if (mode > 1)
4121 switch(Rounding) { 4121 switch(Rounding) {
4122 case 0: goto accept_dig; 4122 case 0: goto accept_dig;
4123 case 2: goto keep_dig; 4123 case 2: goto keep_dig;
4124 } 4124 }
4125 #endif /*Honor_FLT_ROUNDS*/ 4125 #endif /*Honor_FLT_ROUNDS*/
4126 if (j1 > 0) { 4126 if (j1 > 0) {
4127 b = lshift(b, 1); 4127 b = lshift(b, 1);
4128 j1 = cmp(b, S); 4128 j1 = cmp(b, S);
4129 if ((j1 > 0 || (j1 == 0 && dig & 1)) 4129 if ((j1 > 0 || (j1 == 0 && dig & 1))
4130 && dig++ == '9') 4130 && dig++ == '9')
4131 goto round_9_up; 4131 goto round_9_up;
4132 } 4132 }
4133 accept_dig: 4133 accept_dig:
4134 » » » » *s++ = dig; 4134 » » » » *s++ = (char)dig;
4135 goto ret; 4135 goto ret;
4136 } 4136 }
4137 if (j1 > 0) { 4137 if (j1 > 0) {
4138 #ifdef Honor_FLT_ROUNDS 4138 #ifdef Honor_FLT_ROUNDS
4139 if (!Rounding) 4139 if (!Rounding)
4140 goto accept_dig; 4140 goto accept_dig;
4141 #endif 4141 #endif
4142 if (dig == '9') { /* possible if i == 1 */ 4142 if (dig == '9') { /* possible if i == 1 */
4143 round_9_up: 4143 round_9_up:
4144 *s++ = '9'; 4144 *s++ = '9';
4145 goto roundoff; 4145 goto roundoff;
4146 } 4146 }
4147 » » » » *s++ = dig + 1; 4147 » » » » *s++ = (char)dig + 1;
scottmg 2014/09/25 06:44:16 (man this code is frightening) this seems like it
Peter Kasting 2014/09/25 08:31:22 What's even worse is that we have multiple copies
4148 goto ret; 4148 goto ret;
4149 } 4149 }
4150 #ifdef Honor_FLT_ROUNDS 4150 #ifdef Honor_FLT_ROUNDS
4151 keep_dig: 4151 keep_dig:
4152 #endif 4152 #endif
4153 » » » *s++ = dig; 4153 » » » *s++ = (char)dig;
4154 if (i == ilim) 4154 if (i == ilim)
4155 break; 4155 break;
4156 b = multadd(b, 10, 0); 4156 b = multadd(b, 10, 0);
4157 if (mlo == mhi) 4157 if (mlo == mhi)
4158 mlo = mhi = multadd(mhi, 10, 0); 4158 mlo = mhi = multadd(mhi, 10, 0);
4159 else { 4159 else {
4160 mlo = multadd(mlo, 10, 0); 4160 mlo = multadd(mlo, 10, 0);
4161 mhi = multadd(mhi, 10, 0); 4161 mhi = multadd(mhi, 10, 0);
4162 } 4162 }
4163 } 4163 }
4164 } 4164 }
4165 else 4165 else
4166 for(i = 1;; i++) { 4166 for(i = 1;; i++) {
4167 » » » *s++ = dig = quorem(b,S) + '0'; 4167 » » » dig = quorem(b,S) + '0';
4168 » » » *s++ = (char)dig;
4168 if (!b->x[0] && b->wds <= 1) { 4169 if (!b->x[0] && b->wds <= 1) {
4169 #ifdef SET_INEXACT 4170 #ifdef SET_INEXACT
4170 inexact = 0; 4171 inexact = 0;
4171 #endif 4172 #endif
4172 goto ret; 4173 goto ret;
4173 } 4174 }
4174 if (i >= ilim) 4175 if (i >= ilim)
4175 break; 4176 break;
4176 b = multadd(b, 10, 0); 4177 b = multadd(b, 10, 0);
4177 } 4178 }
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
4224 #endif 4225 #endif
4225 Bfree(b); 4226 Bfree(b);
4226 *s = 0; 4227 *s = 0;
4227 *decpt = k + 1; 4228 *decpt = k + 1;
4228 if (rve) 4229 if (rve)
4229 *rve = s; 4230 *rve = s;
4230 return s0; 4231 return s0;
4231 } 4232 }
4232 4233
4233 } // namespace dmg_fp 4234 } // namespace dmg_fp
OLDNEW
« no previous file with comments | « no previous file | base/third_party/dmg_fp/g_fmt.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698