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

* complex.c: some improvements.

* rational.c: ditto.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37757 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
tadf 2012-11-20 12:10:08 +00:00
parent 3b3d2006c2
commit 21453dc738
3 changed files with 69 additions and 25 deletions

View file

@ -1,3 +1,8 @@
Tue Nov 20 21:06:41 2012 Tadayoshi Funaba <tadf@dotrb.org>
* complex.c: some improvements.
* rational.c: ditto.
Tue Nov 20 21:01:16 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
* common.mk (incs): BSD make cannot deal with non-prefixed dependency

View file

@ -1498,13 +1498,19 @@ numeric_to_c(VALUE self)
#include <ctype.h>
inline static int
issign(int c)
{
return (c == '-' || c == '+');
}
static int
read_sign(const char **s,
char **b)
{
int sign = '?';
if (**s == '-' || **s == '+') {
if (issign(**s)) {
sign = **b = **s;
(*s)++;
(*b)++;
@ -1512,16 +1518,22 @@ read_sign(const char **s,
return sign;
}
inline static int
isdecimal(int c)
{
return isdigit((unsigned char)c);
}
static int
read_digits(const char **s, int strict,
char **b)
{
int us = 1;
if (!isdigit((unsigned char)**s))
if (!isdecimal(**s))
return 0;
while (isdigit((unsigned char)**s) || **s == '_') {
while (isdecimal(**s) || **s == '_') {
if (**s == '_') {
if (strict) {
if (us)
@ -1543,6 +1555,12 @@ read_digits(const char **s, int strict,
return 1;
}
inline static int
islettere(int c)
{
return (c == 'e' || c == 'E');
}
static int
read_num(const char **s, int strict,
char **b)
@ -1562,7 +1580,7 @@ read_num(const char **s, int strict,
}
}
if (**s == 'e' || **s == 'E') {
if (islettere(**s)) {
**b = **s;
(*s)++;
(*b)++;
@ -1575,7 +1593,7 @@ read_num(const char **s, int strict,
return 1;
}
static int
inline static int
read_den(const char **s, int strict,
char **b)
{
@ -1612,7 +1630,7 @@ read_rat(const char **s, int strict,
return 1;
}
static int
inline static int
isimagunit(int c)
{
return (c == 'i' || c == 'I' ||
@ -1654,7 +1672,7 @@ read_comp(const char **s, int strict,
**b = '\0';
num = str2num(bb);
*ret = rb_complex_new2(num, ZERO);
return 0; /* e.g. "1/" */
return 0; /* e.g. "-" */
}
**b = '\0';
num = str2num(bb);
@ -1673,9 +1691,9 @@ read_comp(const char **s, int strict,
st = read_rat(s, strict, b);
**b = '\0';
if (strlen(bb) < 1 ||
!isdigit((unsigned char)*(bb + strlen(bb) - 1))) {
!isdecimal(*(bb + strlen(bb) - 1))) {
*ret = rb_complex_new2(num, ZERO);
return 0; /* e.g. "1@x" */
return 0; /* e.g. "1@-" */
}
num2 = str2num(bb);
*ret = rb_complex_polar(num, num2);
@ -1685,7 +1703,7 @@ read_comp(const char **s, int strict,
return 1; /* e.g. "1@2" */
}
if (**s == '-' || **s == '+') {
if (issign(**s)) {
bb = *b;
sign = read_sign(s, b);
if (isimagunit(**s))
@ -1713,7 +1731,7 @@ read_comp(const char **s, int strict,
}
}
static void
inline static void
skip_ws(const char **s)
{
while (isspace((unsigned char)**s))

View file

@ -1958,40 +1958,53 @@ float_rationalize(int argc, VALUE *argv, VALUE self)
#include <ctype.h>
inline static int
issign(int c)
{
return (c == '-' || c == '+');
}
static int
read_sign(const char **s)
{
int sign = '?';
if (**s == '-' || **s == '+') {
if (issign(**s)) {
sign = **s;
(*s)++;
}
return sign;
}
inline static int
isdecimal(int c)
{
return isdigit((unsigned char)c);
}
static int
read_digits(const char **s, int strict,
VALUE *num, int *count)
{
int us = 1;
int us = 1, ret = 1;
const char *b = *s;
if (!isdigit((unsigned char)**s))
if (!isdecimal(**s)) {
*num = ZERO;
return 0;
}
*num = ZERO;
while (isdigit((unsigned char)**s) || **s == '_') {
while (isdecimal(**s) || **s == '_') {
if (**s == '_') {
if (strict) {
if (us)
return 0;
if (us) {
ret = 0;
goto conv;
}
}
us = 1;
}
else {
*num = f_mul(*num, INT2FIX(10));
*num = f_add(*num, INT2FIX(**s - '0'));
if (count)
(*count)++;
us = 0;
@ -2002,7 +2015,15 @@ read_digits(const char **s, int strict,
do {
(*s)--;
} while (**s == '_');
return 1;
conv:
*num = rb_cstr_to_inum(b, 10, 0);
return ret;
}
inline static int
islettere(int c)
{
return (c == 'e' || c == 'E');
}
static int
@ -2034,7 +2055,7 @@ read_num(const char **s, int numsign, int strict,
}
}
if (**s == 'e' || **s == 'E') {
if (islettere(**s)) {
int expsign;
(*s)++;
@ -2054,7 +2075,7 @@ read_num(const char **s, int numsign, int strict,
return 1;
}
static int
inline static int
read_den(const char **s, int strict,
VALUE *num)
{
@ -2093,7 +2114,7 @@ read_rat(const char **s, int strict,
return 1;
}
static void
inline static void
skip_ws(const char **s)
{
while (isspace((unsigned char)**s))