Class: Sollya::Constant

Inherits:
Function show all
Defined in:
ext/sollya_rb.c

Direct Known Subclasses

LibraryConstant, Pi

Instance Method Summary collapse

Methods inherited from Function

#*, #**, #+, #-, #-@, #/, #<, #<=, #>, #>=, #abs, #apply_at, #arity, #autodiff, #ceil, #chebyshevform, #children, #coeff, #coerce, #degree, #denominator, #diff, #dirtyfindzeros, #dirtyintegral, #dirtysimplify, #evaluate, #expand, #findzeros, #floor, #horner, #in, #integral, #nearestint, #nth_child, #numberroots, #numerator, #simplify, #substitute, #taylor

Methods inherited from Object

#!=, #&, #==, #concat, #inspect, #print, #to_s, #to_sollya, #|, #~

Instance Method Details

#to_fFloat

Returns:



3007
3008
3009
3010
3011
3012
3013
3014
# File 'ext/sollya_rb.c', line 3007

static VALUE sollyarb_constant_to_f(VALUE self)
{
  sollya_obj_t cst = sollyarb_object_rb2ref(self);
  double d;
  if (!sollya_lib_get_constant_as_double(&d, cst))
    return Qnil;
  return DBL2NUM(d);
}

#to_mpfrMPFR

Returns:



2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
# File 'ext/sollya_rb.c', line 2985

static VALUE sollyarb_constant_to_mpfr(VALUE self)
{
  sollya_obj_t cst = sollyarb_object_rb2ref(self);
  mp_prec_t prec = 0;
  if (!sollya_lib_get_prec_of_constant(&prec, cst)) {
    sollya_obj_t p = sollya_lib_get_prec();
    sollya_lib_get_constant_as_int64(&prec, p);
    sollya_lib_clear_obj(p);
  }
  if (!prec) return Qnil;
  VALUE mprb = mpfrrb_alloc(c_MPFR);
  mpfr_ptr mp = mpfrrb_rb2ref_ext(mprb);
  mpfr_init2(mp, prec);
  if (!sollya_lib_get_constant(mp, cst)) {
    return Qnil;
  }
  return mprb;
}