Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

Diff of /src/ov-mp.h [a5e8fd] .. [6164d0] Maximize Restore

  Switch to side-by-side view

--- a/src/ov-mp.h
+++ b/src/ov-mp.h
@@ -22,6 +22,10 @@
 // GNU MPFR and GMP
 #include <gmp.h>
 #include <mpfr.h>
+
+// Generic Library
+#include <map>
+
 #include <octave/ov.h>
 #include <octave/oct-alloc.h>
 #include <octave/ov-typeinfo.h>
@@ -35,28 +39,28 @@
 
   octave_mp (void);
   octave_mp (signed long si, mpfr_prec_t sprec = mpfr_get_default_prec (),  mp_rnd_t srnd = mpfr_get_default_rounding_mode ());
+  octave_mp (signed long si, mpfr_prec_t sprec,  const std::string srnd);
+
   octave_mp (unsigned long ui, mpfr_prec_t sprec = mpfr_get_default_prec (),  mp_rnd_t srnd = mpfr_get_default_rounding_mode ());
+  octave_mp (unsigned long ui, mpfr_prec_t sprec,  const std::string srnd);
   
   octave_mp (const octave_mp& s);
 
   octave_mp (const std::string& x, mpfr_prec_t sprec = mpfr_get_default_prec (), mp_rnd_t srnd = mpfr_get_default_rounding_mode ());
+  octave_mp (const std::string& x, mpfr_prec_t sprec, const std::string srnd);
 
   octave_mp (const float& x, mpfr_prec_t sprec = mpfr_get_default_prec (),  mp_rnd_t srnd = mpfr_get_default_rounding_mode ());
+  octave_mp (const float& x, mpfr_prec_t sprec,  const std::string srnd);
+
   octave_mp (const double& x, mpfr_prec_t sprec = mpfr_get_default_prec (),  mp_rnd_t srnd = mpfr_get_default_rounding_mode ());
+  octave_mp (const double& x, mpfr_prec_t sprec, const std::string srnd);
 
   octave_mp (const octave_value& x, mpfr_prec_t sprec = mpfr_get_default_prec (),  mp_rnd_t srnd = mpfr_get_default_rounding_mode ());
+  octave_mp (const octave_value& x, mpfr_prec_t sprec,  const std::string srnd);
 
-  octave_mp (const octave_base_value& x, mpfr_prec_t sprec = mpfr_get_default_prec (),  mp_rnd_t srnd = mpfr_get_default_rounding_mode ());
-
-  ~octave_mp (void) 
-    { 
-      if (0 != (scalar)->_mpfr_d) 
-        {
-          mpfr_clear (scalar);  
-          (scalar)->_mpfr_d = 0;
-        }
-    }
-
+  ~octave_mp (void) { if (0 == scalar->_mpfr_d) return; 
+    mpfr_clear (scalar); scalar->_mpfr_d = 0; }
+        
   OV_REP_TYPE *clone (void) const { return new octave_mp (*this); }
 
 #if 0
@@ -130,12 +134,32 @@
 
   octave_value map (unary_mapper_t umap) const;
   
+  mpfr_rnd_t convert_rnd_mode (const std::string mode);
+ 
+  void commun_string_parser (const std::string src, mp_rnd_t srnd);
+  void commun_ov_parser (const octave_value &x, mp_rnd_t srnd);
+
 private:
   
   mpfr_t scalar;
   static mpfr_prec_t prec;
   mpfr_rnd_t rnd;
+  static std::map<char, int> rndmap;
 
+  static std::map<char, int> initmap() {
+    std::map<char, int> somemap;
+    
+    /* This should match MPFR definitions ! */
+    somemap['N'] = MPFR_RNDN;  /* round to nearest, with ties to even */
+    somemap['Z'] = MPFR_RNDZ;  /* round toward zero */
+    somemap['U'] = MPFR_RNDU;  /* round toward +Inf */
+    somemap['D'] = MPFR_RNDD;  /* round toward -Inf */
+    somemap['A'] = MPFR_RNDA;  /* round away from zero */
+    somemap['F'] = MPFR_RNDF;  /* faithful rounding (not implemented yet) */
+    
+    return somemap;
+  }
+  
   DECLARE_OCTAVE_ALLOCATOR
 
   DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA