Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

2008-10-07 Marek Habersack <mhabersack@novell.com>

	* sysmath.h: changed the declaration of the
	ves_icall_System_Math_Round2 icall by adding an extra
	away_from_zero parameter.

	* sysmath.c (ves_icall_System_Math_Round2): added support for
	away from zero rounding. The icall now takes an extra boolean
	parameter to signal that away from zero operation is requested.

svn path=/trunk/mono/; revision=115080
  • Loading branch information...
commit de876d8a5fbb08aeddbaac762ae2f8bb5ae189ec 1 parent 5c32b6e
@grendello grendello authored
View
10 mono/metadata/ChangeLog
@@ -1,3 +1,13 @@
+2008-10-07 Marek Habersack <mhabersack@novell.com>
+
+ * sysmath.h: changed the declaration of the
+ ves_icall_System_Math_Round2 icall by adding an extra
+ away_from_zero parameter.
+
+ * sysmath.c (ves_icall_System_Math_Round2): added support for
+ away from zero rounding. The icall now takes an extra boolean
+ parameter to signal that away from zero operation is requested.
+
2008-10-06 Zoltan Varga <vargaz@gmail.com>
* marshal.c (mono_marshal_get_delegate_begin_invoke): Put the wrapper in
View
15 mono/metadata/sysmath.c
@@ -48,7 +48,7 @@ gdouble ves_icall_System_Math_Round (gdouble x) {
return int_part;
}
-gdouble ves_icall_System_Math_Round2 (gdouble value, gint32 digits) {
+gdouble ves_icall_System_Math_Round2 (gdouble value, gint32 digits, gboolean away_from_zero) {
double p, int_part, dec_part;
MONO_ARCH_SAVE_REGS;
if (value == HUGE_VAL)
@@ -60,9 +60,18 @@ gdouble ves_icall_System_Math_Round2 (gdouble value, gint32 digits) {
p = pow(10, digits);
dec_part = modf (value, &int_part);
dec_part *= 1000000000000000ULL;
- dec_part = floor(dec_part);
+ if (away_from_zero && dec_part > 0)
+ dec_part = ceil (dec_part);
+ else
+ dec_part = floor (dec_part);
dec_part /= (1000000000000000ULL / p);
- dec_part = ves_icall_System_Math_Round(dec_part);
+ if (away_from_zero) {
+ if (dec_part > 0)
+ dec_part = floor (dec_part + 0.5);
+ else
+ dec_part = ceil (dec_part - 0.5);
+ } else
+ dec_part = ves_icall_System_Math_Round (dec_part);
dec_part /= p;
return int_part + dec_part;
}
View
2  mono/metadata/sysmath.h
@@ -16,7 +16,7 @@
extern gdouble ves_icall_System_Math_Floor (gdouble x) MONO_INTERNAL;
extern gdouble ves_icall_System_Math_Round (gdouble x) MONO_INTERNAL;
-extern gdouble ves_icall_System_Math_Round2 (gdouble value, gint32 digits) MONO_INTERNAL;
+extern gdouble ves_icall_System_Math_Round2 (gdouble value, gint32 digits, gboolean away_from_zero) MONO_INTERNAL;
extern gdouble
ves_icall_System_Math_Sin (gdouble x) MONO_INTERNAL;
Please sign in to comment.
Something went wrong with that request. Please try again.