1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* eval.c (rb_clear_cache_by_class): new function.

* eval.c (set_method_visibility): should have clear cache forq
  updated visibility.

* numeric.c (flo_to_s): default format precision to be "%.16g".

* util.c (ruby_strtod): use own strtod(3) implementation to avoid
  locale hell.  Due to this change "0xff".to_f no longer returns 255.0

* eval.c (avalue_to_yvalue): new function to distinguish yvalue
  (no-arg == Qundef) from svalue (no-arg == Qnil).

* eval.c (rb_yield_0): use avalue_to_yvalue().

* eval.c (assign): warn if val == Qundef where it means rhs is
  void (e.g. yield without value or call without argument).

* parse.y (value_expr): need not to warn for WHILE and UNTIL,
  since they can have return value (via valued break).


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2457 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2002-05-14 06:22:31 +00:00
parent c5d6a1ba48
commit eb6118992b
34 changed files with 377 additions and 70 deletions

View file

@ -4,10 +4,24 @@ Tue May 14 14:49:05 2002 WATANABE Hirofumi <eban@ruby-lang.org>
* missing/strftime.c (timezone): it should take no argument on Cygwin.
Tue May 14 03:07:35 2002 Yukihiro Matsumoto <matz@ruby-lang.org>
* eval.c (rb_clear_cache_by_class): new function.
* eval.c (set_method_visibility): should have clear cache forq
updated visibility.
Mon May 13 14:38:33 2002 WATANABE Hirofumi <eban@ruby-lang.org>
* djgpp/config.hin, djgpp/config.sed: catch up with the latest change.
Mon May 13 01:59:55 2002 Yukihiro Matsumoto <matz@ruby-lang.org>
* numeric.c (flo_to_s): default format precision to be "%.16g".
* util.c (ruby_strtod): use own strtod(3) implementation to avoid
locale hell. Due to this change "0xff".to_f no longer returns 255.0
Sun May 12 03:01:08 2002 WATANABE Hirofumi <eban@ruby-lang.org>
* missing.h: add for missing/*.c.
@ -26,6 +40,16 @@ Sat May 11 10:52:09 2002 Nobuyoshi Nakada <nobu.nokada@softhome.net>
* dir.c (glob_helper): remove escaping backslashes.
Sat May 11 02:46:43 2002 Yukihiro Matsumoto <matz@ruby-lang.org>
* eval.c (avalue_to_yvalue): new function to distinguish yvalue
(no-arg == Qundef) from svalue (no-arg == Qnil).
* eval.c (rb_yield_0): use avalue_to_yvalue().
* eval.c (assign): warn if val == Qundef where it means rhs is
void (e.g. yield without value or call without argument).
Fri May 10 19:00:47 2002 Nobuyoshi Nakada <nobu.nokada@softhome.net>
* parse.y (here_document): preserve line number begins here
@ -38,6 +62,11 @@ Fri May 10 01:55:44 2002 Nobuyoshi Nakada <nobu.nokada@softhome.net>
* eval.c (rb_thread_join_m): new. and added optional argument.
Wed May 8 23:48:40 2002 Yukihiro Matsumoto <matz@ruby-lang.org>
* parse.y (value_expr): need not to warn for WHILE and UNTIL,
since they can have return value (via valued break).
Tue May 7 17:13:40 2002 WATANABE Hirofumi <eban@ruby-lang.org>
* configure.in: forgot to add '-Wl,' to the gcc option on Cygwin/MinGW.

View file

@ -223,9 +223,6 @@ strftime.@OBJEXT@: $(srcdir)/missing/strftime.c
strstr.@OBJEXT@: $(srcdir)/missing/strstr.c
$(CC) $(CFLAGS) $(CPPFLAGS) -c $(srcdir)/missing/strstr.c
strtod.@OBJEXT@: $(srcdir)/missing/strtod.c
$(CC) $(CFLAGS) $(CPPFLAGS) -c $(srcdir)/missing/strtod.c
strtol.@OBJEXT@: $(srcdir)/missing/strtol.c
$(CC) $(CFLAGS) $(CPPFLAGS) -c $(srcdir)/missing/strtol.c

2
ToDo
View file

@ -95,7 +95,7 @@ Standard Libraries
* new user-defined marshal scheme. _dump(dumper), _load(restorer)
* library to load per-user profile seeking .ruby_profile or ruby.ini file.
* warning framework (warn, warning for Ruby level)
* marshal should not depend on sprintf/strtod (works bad with locale).
* marshal should not depend on sprintf (works bad with locale).
* ternary arg pow: a.pow(b,c) == a**b%c
* new caller(), e.g. call_stack; needs better name.
* remove dependency on MAXPATHLEN.

View file

@ -10,9 +10,10 @@
**********************************************************************/
#include "ruby.h"
#include <math.h>
#include <ctype.h>
#include "ruby.h"
VALUE rb_cBignum;

View file

@ -987,7 +987,7 @@ if test "$enable_shared" = 'yes'; then
darwin*)
LIBRUBY_SO='lib$(RUBY_INSTALL_NAME).$(MAJOR).$(MINOR).$(TEENY).dylib'
LIBRUBY_LDSHARED='cc -dynamiclib -undefined suppress -flat_namespace'
LIBRUBY_DLDFLAGS='-install_name lib$(RUBY_INSTALL_NAME).dylib -current_version $(MAJOR).$(MINOR).$(TEENY) -compatibility_version $(MAJOR).$(MINOR)'
LIBRUBY_DLDFLAGS='-install_name $(prefix)/lib/lib$(RUBY_INSTALL_NAME).dylib -current_version $(MAJOR).$(MINOR).$(TEENY) -compatibility_version $(MAJOR).$(MINOR)'
LIBRUBY_ALIASES='lib$(RUBY_INSTALL_NAME).$(MAJOR).$(MINOR).dylib lib$(RUBY_INSTALL_NAME).dylib'
;;
*)

2
dln.c
View file

@ -6,7 +6,7 @@
$Date$
created at: Tue Jan 18 17:05:06 JST 1994
Copyright (C) 1993-2001 Yukihiro Matsumoto
Copyright (C) 1993-2002 Yukihiro Matsumoto
**********************************************************************/

2
dln.h
View file

@ -6,7 +6,7 @@
$Date$
created at: Wed Jan 19 16:53:09 JST 1994
Copyright (C) 1993-2001 Yukihiro Matsumoto
Copyright (C) 1993-2002 Yukihiro Matsumoto
**********************************************************************/

2
env.h
View file

@ -6,7 +6,7 @@
$Date$
created at: Mon Jul 11 11:53:03 JST 1994
Copyright (C) 1993-2001 Yukihiro Matsumoto
Copyright (C) 1993-2002 Yukihiro Matsumoto
**********************************************************************/

62
eval.c
View file

@ -217,6 +217,21 @@ rb_clear_cache_by_id(id)
}
}
static void
rb_clear_cache_by_class(klass)
VALUE klass;
{
struct cache_entry *ent, *end;
ent = cache; end = ent + CACHE_SIZE;
while (ent < end) {
if (ent->origin == klass) {
ent->mid = 0;
}
ent++;
}
}
void
rb_add_method(klass, mid, node, noex)
VALUE klass;
@ -2111,11 +2126,28 @@ avalue_to_svalue(v)
return v;
}
static VALUE
avalue_to_yvalue(v)
VALUE v;
{
if (TYPE(v) != T_ARRAY) {
v = rb_ary_to_ary(v);
}
if (RARRAY(v)->len == 0) {
return Qundef;
}
if (RARRAY(v)->len == 1) {
return RARRAY(v)->ptr[0];
}
return v;
}
static VALUE
svalue_to_mvalue(v)
VALUE v;
{
if (NIL_P(v)) return rb_ary_new2(0);
if (v == Qnil || v == Qundef)
return rb_ary_new2(0);
if (TYPE(v) == T_ARRAY) {
return v;
}
@ -2511,10 +2543,10 @@ rb_eval(self, n)
case NODE_YIELD:
if (node->nd_stts) {
result = avalue_to_svalue(rb_eval(self, node->nd_stts));
result = avalue_to_yvalue(rb_eval(self, node->nd_stts));
}
else {
result = Qnil;
result = Qundef; /* no arg */
}
result = rb_yield_0(result, 0, 0, 0);
break;
@ -3745,21 +3777,21 @@ rb_yield_0(val, self, klass, pcall)
RARRAY(val)->len);
}
}
else if (nd_type(block->var) == NODE_MASGN) {
massign(self, block->var, val, pcall);
}
else {
if (nd_type(block->var) == NODE_MASGN) {
massign(self, block->var, val, pcall);
}
else {
if (pcall) val = avalue_to_svalue(val);
assign(self, block->var, val, pcall);
if (pcall) {
val = avalue_to_yvalue(val);
}
assign(self, block->var, val, pcall);
}
}
POP_TAG();
if (state) goto pop_state;
}
else if (pcall) {
val = avalue_to_svalue(val);
val = avalue_to_yvalue(val);
}
PUSH_ITER(block->iter);
@ -3849,7 +3881,7 @@ static VALUE
rb_f_loop()
{
for (;;) {
rb_yield_0(Qnil, 0, 0, 0);
rb_yield_0(Qundef, 0, 0, 0);
CHECK_INTS;
}
return Qnil; /* dummy */
@ -3912,7 +3944,10 @@ assign(self, lhs, val, pcall)
VALUE val;
int pcall;
{
if (val == Qundef) val = Qnil;
if (val == Qundef) {
rb_warning("assigning void value");
val = Qnil;
}
switch (nd_type(lhs)) {
case NODE_GASGN:
rb_gvar_set(lhs->nd_entry, val);
@ -5623,6 +5658,7 @@ set_method_visibility(self, argc, argv, ex)
for (i=0; i<argc; i++) {
rb_export_method(self, rb_to_id(argv[i]), ex);
}
rb_clear_cache_by_class(self);
}
static VALUE
@ -6470,7 +6506,7 @@ proc_invoke(proc, args, pcall, self)
ruby_frame->iter = ITER_CUR;
if (!pcall) {
args = avalue_to_svalue(args);
args = avalue_to_yvalue(args);
}
PUSH_TAG(PROT_NONE);
state = EXEC_TAG();

2
file.c
View file

@ -6,7 +6,7 @@
$Date$
created at: Mon Nov 15 12:24:34 JST 1993
Copyright (C) 1993-2001 Yukihiro Matsumoto
Copyright (C) 1993-2002 Yukihiro Matsumoto
Copyright (C) 2000 Network Applied Communication Laboratory, Inc.
Copyright (C) 2000 Information-technology Promotion Agency, Japan

13
gc.c
View file

@ -1128,18 +1128,7 @@ rb_gc()
struct gc_list *list;
struct FRAME * volatile frame; /* gcc 2.7.2.3 -O2 bug?? */
jmp_buf save_regs_gc_mark;
#ifdef C_ALLOCA
VALUE stack_end;
alloca(0);
# define STACK_END (&stack_end)
#else
# if defined(__GNUC__) && defined(USE_BUILTIN_FRAME_ADDRESS)
VALUE *stack_end = __builtin_frame_address(0);
# else
VALUE *stack_end = alloca(1);
# endif
# define STACK_END (stack_end)
#endif
SET_STACK_END;
if (dont_gc || during_gc) {
if (!freelist || malloc_memories > GC_MALLOC_LIMIT) {

2
hash.c
View file

@ -6,7 +6,7 @@
$Date$
created at: Mon Nov 22 18:51:18 JST 1993
Copyright (C) 1993-2001 Yukihiro Matsumoto
Copyright (C) 1993-2002 Yukihiro Matsumoto
Copyright (C) 2000 Network Applied Communication Laboratory, Inc.
Copyright (C) 2000 Information-technology Promotion Agency, Japan

View file

@ -15,10 +15,7 @@
#include "ruby.h"
#include "rubyio.h"
#include "st.h"
#if !defined(atof) && !defined(HAVE_STDLIB_H)
double strtod();
#endif
#include "util.h"
#define BITSPERSHORT (2*CHAR_BIT)
#define SHORTMASK ((1<<BITSPERSHORT)-1)
@ -884,7 +881,6 @@ r_object(arg)
d = -1.0 / t;
}
else {
/* xxx: should not use system's strtod(3) */
d = strtod(buf, 0);
}
v = rb_float_new(d);

View file

@ -126,6 +126,9 @@
(defvar ruby-indent-level 2
"*Indentation of ruby statements.")
(defvar ruby-deep-arglist t
"*Deep indent argument lists when non-nil.")
(eval-when-compile (require 'cl))
(defun ruby-imenu-create-index ()
(let ((index-alist '())
@ -366,18 +369,18 @@ The variable ruby-indent-level controls the amount of indentation.
(forward-line 1)
(goto-char (point))
)
((looking-at "(")
((and (looking-at "(") ruby-deep-arglist)
(setq nest (cons (cons (char-after (point)) pnt) nest))
(setq pcol (cons (cons pnt depth) pcol))
(setq depth 0)
(goto-char pnt)
)
((looking-at "[\\[{]")
((looking-at "[\\[{(]")
(setq nest (cons (cons (char-after (point)) pnt) nest))
(setq depth (1+ depth))
(goto-char pnt)
)
((looking-at ")")
((and (looking-at ")") ruby-deep-arglist)
(setq nest (cdr nest))
(setq depth (cdr (car pcol)))
(setq pcol (cdr pcol))
@ -478,7 +481,7 @@ The variable ruby-indent-level controls the amount of indentation.
(setq indent nil)) ; do nothing
((car (nth 1 state)) ; in paren
(goto-char (cdr (nth 1 state)))
(if (eq (car (nth 1 state)) ?\( )
(if (and (eq (car (nth 1 state)) ?\( ) ruby-deep-arglist)
(let ((column (current-column))
(s (ruby-parse-region (point) indent-point)))
(cond

View file

@ -1,6 +1,6 @@
/************************************************
missing.h - prototype for missing/*.c
missing.h - prototype for *.c in ./missing
$Author$
$Date$

2
node.h
View file

@ -6,7 +6,7 @@
$Date$
created at: Fri May 28 15:14:02 JST 1993
Copyright (C) 1993-2001 Yukihiro Matsumoto
Copyright (C) 1993-2002 Yukihiro Matsumoto
**********************************************************************/

View file

@ -6,7 +6,7 @@
$Date$
created at: Fri Aug 13 18:33:09 JST 1993
Copyright (C) 1993-2001 Yukihiro Matsumoto
Copyright (C) 1993-2002 Yukihiro Matsumoto
**********************************************************************/
@ -216,7 +216,7 @@ flo_to_s(flt)
VALUE flt;
{
char buf[24];
char *fmt = "%.10g";
char *fmt = "%.16g";
double value = RFLOAT(flt)->value;
double avalue, d1, d2;
@ -235,11 +235,12 @@ flo_to_s(flt)
d1 = modf(d1, &d2);
if (d1 == 0) fmt = "%.1e";
}
else if (avalue >= 1.0e10) {
else if (avalue >= 1.0e15) {
d1 = avalue;
while (d1 > 10.0) d1 /= 10.0;
d1 = modf(d1, &d2);
if (d1 == 0) fmt = "%.1e";
else fmt = "%.16e";
}
else if ((d1 = modf(value, &d2)) == 0) {
fmt = "%.1f";

View file

@ -14,6 +14,7 @@
#include "ruby.h"
#include "st.h"
#include "util.h"
#include <stdio.h>
#include <errno.h>
#include <ctype.h>
@ -990,7 +991,7 @@ rb_cstr_to_dbl(p, badcheck)
d = strtod(p, &end);
if (p == end) {
if (badcheck) {
bad:
bad:
rb_invalid_str(q, "Float()");
}
return d;

2
pack.c
View file

@ -6,7 +6,7 @@
$Date$
created at: Thu Feb 10 15:17:05 JST 1994
Copyright (C) 1993-2001 Yukihiro Matsumoto
Copyright (C) 1993-2002 Yukihiro Matsumoto
**********************************************************************/

View file

@ -4597,8 +4597,6 @@ value_expr(node)
if (node == 0) return Qtrue;
switch (nd_type(node)) {
case NODE_WHILE:
case NODE_UNTIL:
case NODE_CLASS:
case NODE_MODULE:
case NODE_DEFN:
@ -4612,6 +4610,7 @@ value_expr(node)
case NODE_REDO:
case NODE_RETRY:
yyerror("void value expression");
/* or "control never reach"? */
return Qfalse;
case NODE_BLOCK:

View file

@ -726,7 +726,7 @@ rb_f_fork(obj)
if (rb_block_given_p()) {
int status;
rb_protect(rb_yield, Qnil, &status);
rb_protect(rb_yield, Qundef, &status);
ruby_stop(status);
}
return Qnil;

View file

@ -265,7 +265,7 @@ range_step(argc, argv, range)
}
if (FIXNUM_P(b) && FIXNUM_P(e)) { /* fixnums are special */
long beg, end = FIX2LONG(e), s = NUM2LONG(step);
long end = FIX2LONG(e), s = NUM2LONG(step);
long i;
if (s <= 0) {
rb_raise(rb_eArgError, "step can't be <= 0");

2
re.c
View file

@ -5,7 +5,7 @@
$Author$
created at: Mon Aug 9 18:24:49 JST 1993
Copyright (C) 1993-2001 Yukihiro Matsumoto
Copyright (C) 1993-2002 Yukihiro Matsumoto
**********************************************************************/

2
re.h
View file

@ -6,7 +6,7 @@
$Date$
created at: Thu Sep 30 14:18:32 JST 1993
Copyright (C) 1993-2001 Yukihiro Matsumoto
Copyright (C) 1993-2002 Yukihiro Matsumoto
**********************************************************************/

2
ruby.c
View file

@ -6,7 +6,7 @@
$Date$
created at: Tue Aug 10 12:47:31 JST 1993
Copyright (C) 1993-2001 Yukihiro Matsumoto
Copyright (C) 1993-2002 Yukihiro Matsumoto
Copyright (C) 2000 Network Applied Communication Laboratory, Inc.
Copyright (C) 2000 Information-technology Promotion Agency, Japan

2
ruby.h
View file

@ -5,7 +5,7 @@
$Author$
created at: Thu Jun 10 14:26:32 JST 1993
Copyright (C) 1993-2001 Yukihiro Matsumoto
Copyright (C) 1993-2002 Yukihiro Matsumoto
Copyright (C) 2000 Network Applied Communication Laboratory, Inc.
Copyright (C) 2000 Information-technology Promotion Agency, Japan

View file

@ -6,7 +6,7 @@
$Date$
created at: Fri Nov 12 16:47:09 JST 1993
Copyright (C) 1993-2001 Yukihiro Matsumoto
Copyright (C) 1993-2002 Yukihiro Matsumoto
**********************************************************************/

View file

@ -6,7 +6,7 @@
$Date$
created at: Wed Aug 16 01:15:38 JST 1995
Copyright (C) 1993-2001 Yukihiro Matsumoto
Copyright (C) 1993-2002 Yukihiro Matsumoto
**********************************************************************/

View file

@ -1000,7 +1000,7 @@ proc{
test_ok(!defined?(iii)) # out of scope
loop{iii=5; test_ok(eval("defined? iii")); break}
loop {|iii|
loop {
iii = 10
def dyna_var_check
loop {

View file

@ -6,7 +6,7 @@
$Date$
created at: Tue Dec 20 10:13:44 JST 1994
Copyright (C) 1993-2001 Yukihiro Matsumoto
Copyright (C) 1993-2002 Yukihiro Matsumoto
Copyright (C) 2000 Network Applied Communication Laboratory, Inc.
Copyright (C) 2000 Information-technology Promotion Agency, Japan

View file

@ -6,7 +6,7 @@
$Date$
created at: Tue Mar 22 18:44:30 JST 1995
Copyright (C) 1993-2001 Yukihiro Matsumoto
Copyright (C) 1993-2002 Yukihiro Matsumoto
**********************************************************************/

258
util.c
View file

@ -10,6 +10,8 @@
**********************************************************************/
#include "ruby.h"
#include <stdio.h>
#include <errno.h>
@ -17,8 +19,6 @@
#include "missing/file.h"
#endif
#include "ruby.h"
#include "util.h"
#ifndef HAVE_STRING_H
char *strchr _((char*,char));
@ -643,9 +643,261 @@ ruby_getcwd()
char *buf = xmalloc(size);
while (!getcwd(buf, size)) {
if (errno != ERANGE) rb_sys_fail(NULL);
if (errno != ERANGE) rb_sys_fail(0);
size *= 2;
buf = xrealloc(buf, size);
}
return buf;
}
/* copyright notice for strtod implementation --
*
* Copyright (c) 1988-1993 The Regents of the University of California.
* Copyright (c) 1994 Sun Microsystems, Inc.
*
* Permission to use, copy, modify, and distribute this
* software and its documentation for any purpose and without
* fee is hereby granted, provided that the above copyright
* notice appear in all copies. The University of California
* makes no representations about the suitability of this
* software for any purpose. It is provided "as is" without
* express or implied warranty.
*
*/
#define TRUE 1
#define FALSE 0
static int maxExponent = 511; /* Largest possible base 10 exponent. Any
* exponent larger than this will already
* produce underflow or overflow, so there's
* no need to worry about additional digits.
*/
static double powersOf10[] = { /* Table giving binary powers of 10. Entry */
10.0, /* is 10^2^i. Used to convert decimal */
100.0, /* exponents into floating-point numbers. */
1.0e4,
1.0e8,
1.0e16,
1.0e32,
1.0e64,
1.0e128,
1.0e256
};
/*
*----------------------------------------------------------------------
*
* strtod --
*
* This procedure converts a floating-point number from an ASCII
* decimal representation to internal double-precision format.
*
* Results:
* The return value is the double-precision floating-point
* representation of the characters in string. If endPtr isn't
* NULL, then *endPtr is filled in with the address of the
* next character after the last one that was part of the
* floating-point number.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
double
ruby_strtod(string, endPtr)
const char *string; /* A decimal ASCII floating-point number,
* optionally preceded by white space.
* Must have form "-I.FE-X", where I is the
* integer part of the mantissa, F is the
* fractional part of the mantissa, and X
* is the exponent. Either of the signs
* may be "+", "-", or omitted. Either I
* or F may be omitted, or both. The decimal
* point isn't necessary unless F is present.
* The "E" may actually be an "e". E and X
* may both be omitted (but not just one).
*/
char **endPtr; /* If non-NULL, store terminating character's
* address here. */
{
int sign, expSign = FALSE;
double fraction, dblExp, *d;
register const char *p;
register int c;
int exp = 0; /* Exponent read from "EX" field. */
int fracExp = 0; /* Exponent that derives from the fractional
* part. Under normal circumstatnces, it is
* the negative of the number of digits in F.
* However, if I is very long, the last digits
* of I get dropped (otherwise a long I with a
* large negative exponent could cause an
* unnecessary overflow on I alone). In this
* case, fracExp is incremented one for each
* dropped digit. */
int mantSize; /* Number of digits in mantissa. */
int decPt; /* Number of mantissa digits BEFORE decimal
* point. */
const char *pExp; /* Temporarily holds location of exponent
* in string. */
/*
* Strip off leading blanks and check for a sign.
*/
p = string;
while (isspace(*p)) {
p += 1;
}
if (*p == '-') {
sign = TRUE;
p += 1;
}
else {
if (*p == '+') {
p += 1;
}
sign = FALSE;
}
/*
* Count the number of digits in the mantissa (including the decimal
* point), and also locate the decimal point.
*/
decPt = -1;
for (mantSize = 0; ; mantSize += 1) {
c = *p;
if (!isdigit(c)) {
if ((c != '.') || (decPt >= 0)) {
break;
}
decPt = mantSize;
}
p += 1;
}
/*
* Now suck up the digits in the mantissa. Use two integers to
* collect 9 digits each (this is faster than using floating-point).
* If the mantissa has more than 18 digits, ignore the extras, since
* they can't affect the value anyway.
*/
pExp = p;
p -= mantSize;
if (decPt < 0) {
decPt = mantSize;
}
else {
mantSize -= 1; /* One of the digits was the point. */
}
if (mantSize > 18) {
fracExp = decPt - 18;
mantSize = 18;
}
else {
fracExp = decPt - mantSize;
}
if (mantSize == 0) {
fraction = 0.0;
p = string;
goto done;
}
else {
int frac1, frac2;
frac1 = 0;
for ( ; mantSize > 9; mantSize -= 1) {
c = *p;
p += 1;
if (c == '.') {
c = *p;
p += 1;
}
frac1 = 10*frac1 + (c - '0');
}
frac2 = 0;
for (; mantSize > 0; mantSize -= 1) {
c = *p;
p += 1;
if (c == '.') {
c = *p;
p += 1;
}
frac2 = 10*frac2 + (c - '0');
}
fraction = (1.0e9 * frac1) + frac2;
}
/*
* Skim off the exponent.
*/
p = pExp;
if ((*p == 'E') || (*p == 'e')) {
p += 1;
if (*p == '-') {
expSign = TRUE;
p += 1;
}
else {
if (*p == '+') {
p += 1;
}
expSign = FALSE;
}
while (isdigit(*p)) {
exp = exp * 10 + (*p - '0');
p += 1;
}
}
if (expSign) {
exp = fracExp - exp;
}
else {
exp = fracExp + exp;
}
/*
* Generate a floating-point number that represents the exponent.
* Do this by processing the exponent one bit at a time to combine
* many powers of 2 of 10. Then combine the exponent with the
* fraction.
*/
if (exp < 0) {
expSign = TRUE;
exp = -exp;
}
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) {
dblExp *= *d;
}
}
if (expSign) {
fraction /= dblExp;
}
else {
fraction *= dblExp;
}
done:
if (endPtr != NULL) {
*endPtr = (char *) p;
}
if (sign) {
return -fraction;
}
return fraction;
}

5
util.h
View file

@ -6,7 +6,7 @@
$Date$
created at: Thu Mar 9 11:55:53 JST 1995
Copyright (C) 1993-2001 Yukihiro Matsumoto
Copyright (C) 1993-2002 Yukihiro Matsumoto
**********************************************************************/
@ -61,4 +61,7 @@ char *ruby_strdup _((const char*));
char *ruby_getcwd _((void));
#define my_getcwd() ruby_getcwd()
double ruby_strtod _((const char*, char **));
#define strtod(s,e) ruby_strtod((s),(e))
#endif /* UTIL_H */

View file

@ -6,7 +6,7 @@
$Date$
created at: Tue Apr 19 23:55:15 JST 1994
Copyright (C) 1993-2001 Yukihiro Matsumoto
Copyright (C) 1993-2002 Yukihiro Matsumoto
Copyright (C) 2000 Network Applied Communication Laboratory, Inc.
Copyright (C) 2000 Information-technology Promotion Agency, Japan