mirror of
				https://github.com/ruby/ruby.git
				synced 2022-11-09 12:17:21 -05:00 
			
		
		
		
	* util.c (ruby_strtod): improved conversion accuracy.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3692 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
		
							parent
							
								
									57c6f017a0
								
							
						
					
					
						commit
						6940597692
					
				
					 2 changed files with 84 additions and 57 deletions
				
			
		|  | @ -1,3 +1,7 @@ | |||
| Fri Apr 18 01:49:18 2003  Nobuyoshi Nakada  <nobu.nokada@softhome.net> | ||||
| 
 | ||||
| 	* util.c (ruby_strtod): improved conversion accuracy. | ||||
| 
 | ||||
| Thu Apr 17 14:39:23 2003  NAKAMURA Usaku <usa@ruby-lang.org> | ||||
| 
 | ||||
| 	* ext/dbm/dbm.c (each_pair): add prototype to avoid VC++ warnings. | ||||
|  |  | |||
							
								
								
									
										43
									
								
								util.c
									
										
									
									
									
								
							
							
						
						
									
										43
									
								
								util.c
									
										
									
									
									
								
							|  | @ -806,7 +806,6 @@ ruby_strtod(string, endPtr) | |||
|     if (mantSize == 0) { | ||||
| 	fraction = 0.0; | ||||
| 	p = string; | ||||
| 	goto done; | ||||
|     } | ||||
|     else { | ||||
| 	int frac1, frac2; | ||||
|  | @ -830,8 +829,6 @@ ruby_strtod(string, endPtr) | |||
| 	    } | ||||
| 	    frac2 = 10*frac2 + (c - '0'); | ||||
| 	} | ||||
| 	fraction = (1.0e9 * frac1) + frac2; | ||||
|     } | ||||
| 
 | ||||
| 	/*
 | ||||
| 	 * Skim off the exponent. | ||||
|  | @ -869,6 +866,16 @@ ruby_strtod(string, endPtr) | |||
| 	 * fraction. | ||||
| 	 */ | ||||
|      | ||||
| 	if (exp > maxExponent) { | ||||
| 	    exp = maxExponent; | ||||
| 	    errno = ERANGE; | ||||
| 	} | ||||
| 	else if (exp < -maxExponent) { | ||||
| 	    exp = -maxExponent; | ||||
| 	    errno = ERANGE; | ||||
| 	} | ||||
| 	fracExp = exp; | ||||
| 	exp += 9; | ||||
| 	if (exp < 0) { | ||||
| 	    expSign = TRUE; | ||||
| 	    exp = -exp; | ||||
|  | @ -876,10 +883,6 @@ ruby_strtod(string, endPtr) | |||
| 	else { | ||||
| 	    expSign = FALSE; | ||||
| 	} | ||||
|     if (exp > maxExponent) { | ||||
| 	exp = maxExponent; | ||||
| 	errno = ERANGE; | ||||
|     } | ||||
| 	dblExp = 1.0; | ||||
| 	for (d = powersOf10; exp != 0; exp >>= 1, d += 1) { | ||||
| 	    if (exp & 01) { | ||||
|  | @ -887,13 +890,33 @@ ruby_strtod(string, endPtr) | |||
| 	    } | ||||
| 	} | ||||
| 	if (expSign) { | ||||
| 	fraction /= dblExp; | ||||
| 	    fraction = frac1 / dblExp; | ||||
| 	} | ||||
| 	else { | ||||
| 	fraction *= dblExp; | ||||
| 	    fraction = frac1 * dblExp; | ||||
| 	} | ||||
| 	exp = fracExp; | ||||
| 	if (exp < 0) { | ||||
| 	    expSign = TRUE; | ||||
| 	    exp = -exp; | ||||
| 	} | ||||
| 	else { | ||||
| 	    expSign = FALSE; | ||||
| 	} | ||||
| 	dblExp = 1.0; | ||||
| 	for (d = powersOf10; exp != 0; exp >>= 1, d += 1) { | ||||
| 	    if (exp & 01) { | ||||
| 		dblExp *= *d; | ||||
| 	    } | ||||
| 	} | ||||
| 	if (expSign) { | ||||
| 	    fraction += frac2 / dblExp; | ||||
| 	} | ||||
| 	else { | ||||
| 	    fraction += frac2 * dblExp; | ||||
| 	} | ||||
|     } | ||||
| 
 | ||||
| done: | ||||
|     if (endPtr != NULL) { | ||||
| 	*endPtr = (char *) p; | ||||
|     } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 nobu
						nobu