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

Close

[214b68]: src / ov-mp.h Maximize Restore History

Download this file

ov-mp.h    137 lines (94 with data), 4.8 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*
Copyright (C) 2014 Pascal Dupuis <cdemills@gmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; If not, see <http://www.gnu.org/licenses/>.
*/
#if !defined (ov_mp_h)
#define ov_mp_h 1
// GNU MPFR and GMP
#include <gmp.h>
#include <mpfr.h>
#include <octave/ov.h>
#include <octave/oct-alloc.h>
#include <octave/ov-typeinfo.h>
// mp values.
class
octave_mp : public octave_base_value
{
public:
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 (unsigned long ui, mpfr_prec_t sprec = mpfr_get_default_prec (), mp_rnd_t srnd = mpfr_get_default_rounding_mode ());
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 float& 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 = mpfr_get_default_prec (), mp_rnd_t srnd = mpfr_get_default_rounding_mode ());
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_base_value& x, mpfr_prec_t sprec = mpfr_get_default_prec (), mp_rnd_t srnd = mpfr_get_default_rounding_mode ());
~octave_mp (void) { mpfr_clear (scalar); }
OV_REP_TYPE *clone (void) const { return new octave_mp (*this); }
#if 0
void *operator new (size_t size);
void operator delete (void *p, size_t size);
#endif
type_conv_info numeric_conversion_function (void) const;
dim_vector dims (void) const { static dim_vector dv (1, 1); return dv; }
int rows (void) const { return 1; }
int columns (void) const { return 1; }
bool is_constant (void) const { return true; }
bool is_defined (void) const { return true; }
bool is_real_scalar (void) const { return true; }
octave_value all (void) const { return (double) (mpfr_regular_p (scalar)); }
octave_value any (void) const { return (double) (mpfr_regular_p (scalar)); }
bool is_real_type (void) const { return true; }
bool is_scalar_type (void) const { return true; }
bool is_mp_type (void) const { return true; }
/* instead of downclassing, upclass both arguments */
octave_value oct_monocmp_proxy (const octave_mp& a1,
int (*func) (mpfr_srcptr op1));
octave_value oct_monop_proxy (const octave_mp& a1,
int (*func) (mpfr_ptr rop, mpfr_srcptr op1, mpfr_rnd_t rnd));
octave_value oct_bincmp_proxy (const octave_base_value& a1,
const octave_base_value& a2,
int (*func) (mpfr_srcptr op1, mpfr_srcptr op2));
octave_value oct_binop_proxy (const octave_base_value& a1,
const octave_base_value& a2,
int (*func) (mpfr_ptr rop, mpfr_srcptr op1, mpfr_srcptr op2, mpfr_rnd_t rnd));
bool valid_as_scalar_index (void) const
{
mpfr_t one;
int mpeq;
mpfr_init_set_ui (one, 1, rnd);
mpeq = mpfr_equal_p (scalar, one);
mpfr_clear (one);
return (bool) mpeq;
}
bool valid_as_zero_index (void) const
{ return mpfr_zero_p(scalar); }
bool is_true (void) const { return (mpfr_regular_p (scalar)); }
long int long_value (bool = false) const { return mpfr_get_si (scalar, rnd); }
unsigned long int ulong_value (bool = false) const { return mpfr_get_ui (scalar, rnd); }
float float_value (bool = false) const { return mpfr_get_flt (scalar, rnd); }
double double_value (bool = false) const { return mpfr_get_d (scalar, rnd); }
double mp_value (bool = false) const { return 42; }
octave_value hermitian (void) const { return new octave_mp (*this); }
void increment (void) { mpfr_add_ui(scalar, scalar, 1, rnd); }
void decrement (void) { mpfr_sub_ui(scalar, scalar, 1, rnd); }
void print (std::ostream& os, bool pr_as_read_syntax = false) const;
octave_value map (unary_mapper_t umap) const;
private:
mpfr_t scalar;
static mpfr_prec_t prec;
mpfr_rnd_t rnd;
DECLARE_OCTAVE_ALLOCATOR
DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA
};
#endif