mirror of
https://github.com/ruby/ruby.git
synced 2025-08-24 05:25:34 +02:00
parse.y: parse_rational
* parse.y (parse_rational): extract from parse_numeric(). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46844 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
f180814e9d
commit
9e09b370c1
1 changed files with 12 additions and 5 deletions
17
parse.y
17
parse.y
|
@ -6938,6 +6938,17 @@ parser_prepare(struct parser_params *parser)
|
||||||
space_seen && !ISSPACE(c) && \
|
space_seen && !ISSPACE(c) && \
|
||||||
(ambiguous_operator(op, syn), 0)))
|
(ambiguous_operator(op, syn), 0)))
|
||||||
|
|
||||||
|
static VALUE
|
||||||
|
parse_rational(struct parser_params *parser, char *str, int len, int seen_point)
|
||||||
|
{
|
||||||
|
VALUE v;
|
||||||
|
char *point = &str[seen_point];
|
||||||
|
size_t fraclen = len-seen_point-1;
|
||||||
|
memmove(point, point+1, fraclen+1);
|
||||||
|
v = rb_cstr_to_inum(str, 10, FALSE);
|
||||||
|
return rb_rational_new(v, rb_int_positive_pow(10, fraclen));
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
parse_numeric(struct parser_params *parser, int c)
|
parse_numeric(struct parser_params *parser, int c)
|
||||||
{
|
{
|
||||||
|
@ -7156,12 +7167,8 @@ parse_numeric(struct parser_params *parser, int c)
|
||||||
|
|
||||||
suffix = number_literal_suffix(seen_e ? NUM_SUFFIX_I : NUM_SUFFIX_ALL);
|
suffix = number_literal_suffix(seen_e ? NUM_SUFFIX_I : NUM_SUFFIX_ALL);
|
||||||
if (suffix & NUM_SUFFIX_R) {
|
if (suffix & NUM_SUFFIX_R) {
|
||||||
char *point = &tok()[seen_point];
|
|
||||||
size_t fraclen = toklen()-seen_point-1;
|
|
||||||
type = tRATIONAL;
|
type = tRATIONAL;
|
||||||
memmove(point, point+1, fraclen+1);
|
v = parse_rational(parser, tok(), toklen(), seen_point);
|
||||||
v = rb_cstr_to_inum(tok(), 10, FALSE);
|
|
||||||
v = rb_rational_new(v, rb_int_positive_pow(10, fraclen));
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
double d = strtod(tok(), 0);
|
double d = strtod(tok(), 0);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue