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
ee30c5a4
Commit
ee30c5a4
authored
Apr 27, 2012
by
Yukihiro Matsumoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
allow float/double switch
parent
c8f8f839
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
32 deletions
+15
-32
include/mrbconf.h
include/mrbconf.h
+9
-2
src/numeric.c
src/numeric.c
+6
-30
No files found.
include/mrbconf.h
View file @
ee30c5a4
...
...
@@ -8,12 +8,19 @@
#define MRUBYCONF_H
#include <stdint.h>
#define MRB_USE_FLOAT
#ifdef MRB_USE_FLOAT
typedef
float
mrb_float
;
#define readfloat(p) strtof((p),NULL)
#else
typedef
double
mrb_float
;
#define readfloat(p) strtod((p),NULL)
#endif
typedef
int32_t
mrb_int
;
typedef
intptr_t
mrb_sym
;
#define readint(p,base) strtol((p),NULL,(base))
#define readfloat(p) strtod((p),NULL)
#undef INCLUDE_ENCODING
/* not use encoding classes (ascii only) */
#define INCLUDE_ENCODING
/* use UTF-8 encoding classes */
...
...
src/numeric.c
View file @
ee30c5a4
...
...
@@ -101,29 +101,14 @@ const unsigned char mrb_nan[] = "\x00\x00\xc0\x7f";
const
unsigned
char
mrb_nan
[]
=
"
\x7f\xc0\x00\x00
"
;
#endif
extern
double
round
(
double
);
#ifndef HAVE_ROUND
double
round
(
double
x
)
{
double
f
;
if
(
x
>
0
.
0
)
{
f
=
floor
(
x
);
x
=
f
+
(
x
-
f
>=
0
.
5
);
}
else
if
(
x
<
0
.
0
)
{
f
=
ceil
(
x
);
x
=
f
-
(
f
-
x
>=
0
.
5
);
}
return
x
;
}
#ifdef MRB_USE_FLOAT
#define round(f) roundf(f)
#define floor(f) floorf(f)
#define ceil(f) ceilf(f)
#define floor(f) floorf(f)
#define fmod(x,y) fmodf(x,y)
#endif
void
mrb_cmperr
(
mrb_state
*
mrb
,
mrb_value
x
,
mrb_value
y
);
void
...
...
@@ -459,16 +444,7 @@ flodivmod(mrb_state *mrb, mrb_float x, mrb_float y, mrb_float *divp, mrb_float *
mrb_float
div
,
mod
;
if
(
y
==
0
.
0
)
mrb_num_zerodiv
(
mrb
);
#ifdef HAVE_FMOD
mod
=
fmod
(
x
,
y
);
#else
{
mrb_float
z
;
modf
(
x
/
y
,
&
z
);
mod
=
x
-
z
*
y
;
}
#endif
if
(
isinf
(
x
)
&&
!
isinf
(
y
)
&&
!
isnan
(
y
))
div
=
x
;
else
...
...
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