Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mruby
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
mruby
Commits
c6c4da8c
Commit
c6c4da8c
authored
Oct 28, 2012
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #510 from masuidrive/master
define convert method mrb_int/mrb_float with C string
parents
d7d5c15b
15f46a1f
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
21 additions
and
14 deletions
+21
-14
include/mrbconf.h
include/mrbconf.h
+8
-1
src/codegen.c
src/codegen.c
+2
-2
src/dump.c
src/dump.c
+4
-4
src/load.c
src/load.c
+2
-2
src/numeric.c
src/numeric.c
+5
-5
No files found.
include/mrbconf.h
View file @
c6c4da8c
...
...
@@ -55,19 +55,26 @@
#ifdef MRB_USE_FLOAT
typedef
float
mrb_float
;
#define mrb_float_to_str(buf, i) sprintf((buf), "%.7e", (i))
#define str_to_mrb_float(buf) (mrb_float)strtof((buf),NULL)
#else
typedef
double
mrb_float
;
#define mrb_float_to_str(buf, i) sprintf((buf), "%.16e", (i))
#define str_to_mrb_float(buf) (mrb_float)strtod((buf),NULL)
#endif
#define readfloat(p) (mrb_float)strtod((p),NULL)
#ifdef MRB_NAN_BOXING
typedef
int32_t
mrb_int
;
#define MRB_INT_MIN INT32_MIN
#define MRB_INT_MAX INT32_MAX
#define mrb_int_to_str(buf, i) sprintf((buf), "%d", (i))
#define str_to_mrb_int(buf) (mrb_int)strtol((buf), NULL, 10);
#else
typedef
int
mrb_int
;
#define MRB_INT_MIN INT_MIN
#define MRB_INT_MAX INT_MAX
#define mrb_int_to_str(buf, i) sprintf((buf), "%d", (i))
#define str_to_mrb_int(buf) (mrb_int)strtol((buf), NULL, 10);
#endif
typedef
short
mrb_sym
;
...
...
src/codegen.c
View file @
c6c4da8c
...
...
@@ -1741,7 +1741,7 @@ codegen(codegen_scope *s, node *tree, int val)
case
NODE_FLOAT
:
if
(
val
)
{
char
*
p
=
(
char
*
)
tree
;
mrb_float
f
=
read
float
(
p
);
mrb_float
f
=
str_to_mrb_
float
(
p
);
int
off
=
new_lit
(
s
,
mrb_float_value
(
f
));
genop
(
s
,
MKOP_ABx
(
OP_LOADL
,
cursp
(),
off
));
...
...
@@ -1757,7 +1757,7 @@ codegen(codegen_scope *s, node *tree, int val)
case
NODE_FLOAT
:
{
char
*
p
=
(
char
*
)
tree
;
mrb_float
f
=
read
float
(
p
);
mrb_float
f
=
str_to_mrb_
float
(
p
);
int
off
=
new_lit
(
s
,
mrb_float_value
(
-
f
));
genop
(
s
,
MKOP_ABx
(
OP_LOADL
,
cursp
(),
off
));
...
...
src/dump.c
View file @
c6c4da8c
...
...
@@ -226,11 +226,11 @@ get_pool_block_size(mrb_state *mrb, mrb_irep *irep, int type)
switch
(
mrb_type
(
irep
->
pool
[
pool_no
]))
{
case
MRB_TT_FIXNUM
:
len
=
sprintf
(
buf
,
"%d"
,
mrb_fixnum
(
irep
->
pool
[
pool_no
]));
len
=
mrb_int_to_str
(
buf
,
mrb_fixnum
(
irep
->
pool
[
pool_no
]));
size
+=
(
uint32_t
)
len
;
break
;
case
MRB_TT_FLOAT
:
len
=
sprintf
(
buf
,
"%.16e"
,
mrb_float
(
irep
->
pool
[
pool_no
]));
len
=
mrb_float_to_str
(
buf
,
mrb_float
(
irep
->
pool
[
pool_no
]));
size
+=
(
uint32_t
)
len
;
break
;
case
MRB_TT_STRING
:
...
...
@@ -346,11 +346,11 @@ write_pool_block(mrb_state *mrb, mrb_irep *irep, char *buf, int type)
switch
(
mrb_type
(
irep
->
pool
[
pool_no
]))
{
case
MRB_TT_FIXNUM
:
len
=
sprintf
(
char_buf
,
"%d"
,
mrb_fixnum
(
irep
->
pool
[
pool_no
]));
len
=
mrb_int_to_str
(
char_buf
,
mrb_fixnum
(
irep
->
pool
[
pool_no
]));
break
;
case
MRB_TT_FLOAT
:
len
=
sprintf
(
char_buf
,
"%.16e"
,
mrb_float
(
irep
->
pool
[
pool_no
]));
len
=
mrb_float_to_str
(
char_buf
,
mrb_float
(
irep
->
pool
[
pool_no
]));
break
;
case
MRB_TT_STRING
:
...
...
src/load.c
View file @
c6c4da8c
...
...
@@ -405,12 +405,12 @@ read_rite_irep_record(mrb_state *mrb, unsigned char *src, mrb_irep *irep, uint32
switch
(
tt
)
{
//pool data
case
MRB_TT_FIXNUM
:
fix_num
=
str
tol
(
buf
,
NULL
,
10
);
fix_num
=
str
_to_mrb_int
(
buf
);
irep
->
pool
[
i
]
=
mrb_fixnum_value
(
fix_num
);
break
;
case
MRB_TT_FLOAT
:
f
=
read
float
(
buf
);
f
=
str_to_mrb_
float
(
buf
);
irep
->
pool
[
i
]
=
mrb_float_value
(
f
);
break
;
...
...
src/numeric.c
View file @
c6c4da8c
...
...
@@ -246,8 +246,8 @@ flodivmod(mrb_state *mrb, mrb_float x, mrb_float y, mrb_float *divp, mrb_float *
mrb_float
div
,
mod
;
if
(
y
==
0
.
0
)
{
*
divp
=
str
tod
(
"inf"
,
NULL
);
*
modp
=
str
tod
(
"nan"
,
NULL
);
*
divp
=
str
_to_mrb_float
(
"inf"
);
*
modp
=
str
_to_mrb_float
(
"nan"
);
return
;
}
mod
=
fmod
(
x
,
y
);
...
...
@@ -778,7 +778,7 @@ fix_mod(mrb_state *mrb, mrb_value x)
mrb_int
mod
;
if
(
mrb_fixnum
(
y
)
==
0
)
{
return
mrb_float_value
(
str
tod
(
"nan"
,
NULL
));
return
mrb_float_value
(
str
_to_mrb_float
(
"nan"
));
}
fixdivmod
(
mrb
,
a
,
mrb_fixnum
(
y
),
0
,
&
mod
);
return
mrb_fixnum_value
(
mod
);
...
...
@@ -807,8 +807,8 @@ fix_divmod(mrb_state *mrb, mrb_value x)
mrb_int
div
,
mod
;
if
(
mrb_fixnum
(
y
)
==
0
)
{
return
mrb_assoc_new
(
mrb
,
mrb_float_value
(
str
tod
(
"inf"
,
NULL
)),
mrb_float_value
(
str
tod
(
"nan"
,
NULL
)));
return
mrb_assoc_new
(
mrb
,
mrb_float_value
(
str
_to_mrb_float
(
"inf"
)),
mrb_float_value
(
str
_to_mrb_float
(
"nan"
)));
}
fixdivmod
(
mrb
,
mrb_fixnum
(
x
),
mrb_fixnum
(
y
),
&
div
,
&
mod
);
return
mrb_assoc_new
(
mrb
,
mrb_fixnum_value
(
div
),
mrb_fixnum_value
(
mod
));
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment