summaryrefslogtreecommitdiff
path: root/internal.h
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-11-05 09:49:39 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-11-05 09:49:39 +0000
commitdfe91fcd08e7e255b5cb1b306e53bea1ddb54e5f (patch)
treed209f0b546e45cb8d8fa7fc2bbbb5044e53e2c8f /internal.h
parent76977611dd68e384fdce8c546efda5e1931e67a6 (diff)
numeric.c: round to nearest even
* numeric.c (flo_round, int_round): support round-to-nearest-even semantics of IEEE 754 to match sprintf behavior, and add `half:` optional keyword argument for the old behavior. [ruby-core:76273] [Bug #12548] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56590 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'internal.h')
-rw-r--r--internal.h14
1 files changed, 13 insertions, 1 deletions
diff --git a/internal.h b/internal.h
index 847de98eee..7522122844 100644
--- a/internal.h
+++ b/internal.h
@@ -1135,6 +1135,17 @@ VALUE rb_math_sqrt(VALUE);
void Init_newline(void);
/* numeric.c */
+#ifndef ROUND_DEFAULT
+# define ROUND_DEFAULT RUBY_NUM_ROUND_HALF_EVEN
+#endif
+enum ruby_num_rounding_mode {
+ RUBY_NUM_ROUND_HALF_UP,
+ RUBY_NUM_ROUND_HALF_EVEN,
+ RUBY_NUM_ROUND_DEFAULT = ROUND_DEFAULT
+};
+#define ROUND_TO(mode, up, even) \
+ ((mode) == RUBY_NUM_ROUND_HALF_EVEN ? even : up)
+
int rb_num_to_uint(VALUE val, unsigned int *ret);
VALUE ruby_num_interval_step_size(VALUE from, VALUE to, VALUE step, int excl);
int ruby_float_step(VALUE from, VALUE to, VALUE step, int excl);
@@ -1148,11 +1159,12 @@ VALUE rb_int_minus(VALUE x, VALUE y);
VALUE rb_int_mul(VALUE x, VALUE y);
VALUE rb_int_idiv(VALUE x, VALUE y);
VALUE rb_int_modulo(VALUE x, VALUE y);
-VALUE rb_int_round(VALUE num, int ndigits);
+VALUE rb_int_round(VALUE num, int ndigits, enum ruby_num_rounding_mode mode);
VALUE rb_int2str(VALUE num, int base);
VALUE rb_dbl_hash(double d);
VALUE rb_fix_plus(VALUE x, VALUE y);
VALUE rb_int_ge(VALUE x, VALUE y);
+enum ruby_num_rounding_mode rb_num_get_rounding_option(VALUE opts);
#if USE_FLONUM
#define RUBY_BIT_ROTL(v, n) (((v) << (n)) | ((v) >> ((sizeof(v) * 8) - n)))