Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
r""" Generic numerical approximation function """
#***************************************************************************** # Copyright (C) 2016 Jeroen Demeyer <jdemeyer@cage.ugent.be> # # 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 2 of the License, or # (at your option) any later version. # http://www.gnu.org/licenses/ #*****************************************************************************
from sage.structure.parent cimport Parent from sage.structure.element cimport parent cdef Parent CDF
""" Generic implementation of ``numerical_approx`` using coercion or conversion to a real or complex field.
EXAMPLES::
sage: from sage.arith.numerical_approx import numerical_approx_generic sage: numerical_approx_generic(pi, 20) 3.1416 sage: numerical_approx_generic(int(42), 20) 42.000 sage: numerical_approx_generic(float(4.2), 20) 4.2000 """
# Coercion didn't work: there are 3 possibilities: # (1) There is a coercion possible to a lower precision # (2) There is a conversion but no coercion # (3) The type doesn't convert at all
# Figure out input precision to check for case (1) # If we can coerce to CDF, assume input precision was 53 bits else: # Otherwise, assume precision wasn't the issue
# The issue is not precision, try conversion instead |