Permalink
Browse files

initial checkin (floor and ceil with n decimals)

  • Loading branch information...
1 parent 96c245d commit 218447fa5a90cebc1798dd9a892acfb1b951b1cd @ettore committed Feb 3, 2012
Showing with 49 additions and 0 deletions.
  1. +24 −0 clcg_math.h
  2. +25 −0 clcg_math.m
View
@@ -0,0 +1,24 @@
+//
+// clcg_math.h
+// Goodreads
+//
+// Created by Ettore Pasquini on 2/2/12.
+// Copyright (c) 2012 Goodreads. All rights reserved.
+//
+
+#ifndef CLCG_MATH_H_
+#define CLCG_MATH_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+ double clcg_floor(double n, unsigned decimals);
+
+ double clcg_ceil(double n, unsigned decimals);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
View
@@ -0,0 +1,25 @@
+//
+// clcg_math.m
+// Goodreads
+//
+// Created by Ettore Pasquini on 2/2/12.
+// Copyright (c) 2012 Goodreads. All rights reserved.
+//
+
+#include <math.h>
+
+#import "clcg_math.h"
+
+
+double clcg_floor(double n, unsigned decimals)
+{
+ double mul = pow(10, decimals);
+ return floor(n * mul) / mul;
+}
+
+
+double clcg_ceil(double n, unsigned decimals)
+{
+ double mul = pow(10, decimals);
+ return ceil(n * mul) / mul;
+}

0 comments on commit 218447f

Please sign in to comment.