Révision 155 pobysoPythonSage/src/pobyso.py

pobyso.py (revision 155)
282 282
    return(constSa.value)
283 283
# End pobyso_constant_from_int_so_sa
284 284

  
285
def pobyso_error_so():
286
    return sollya_lib_error(None)
287
# End pobyso_error().
288

  
285 289
def pobyso_function_type_as_string(funcType):
286 290
    """ Legacy function. See pobyso_function_type_as_string_so_sa. """
287 291
    return(pobyso_function_type_as_string_so_sa(funcType))
......
761 765
    return(int(prec.value))
762 766
# End pobyso_get_prec_of_range_so_sa()
763 767

  
764
def pobyso_guess_degree_sa_sa(functionSa, intervalSa, errorSa, weightSa=None, \
765
                              degreeBoundSa=None):
768
def pobyso_guess_degree_sa_sa(functionSa, intervalSa, approxErrorSa, 
769
                              weightSa=None, degreeBoundSa=None):
770
    """
771
    Sa_sa variant of the solly_guessdegree function.
772
    Return 0 if something goes wrong.
773
    """
766 774
    functionAsStringSa = functionSa._assume_str()
767 775
    functionSo = pobyso_parse_string_sa_so(functionAsStringSa)
776
    if pobyso_is_error_so_sa(functionSo):
777
        sollya_lib_clear_obj(functionSo)
778
        return 0
768 779
    rangeSo = pobyso_interval_to_range_sa_so(intervalSa)
769
    errorSo = pobyso_constant_sa_so(errorSa)
780
    # The approximation error is expected to be a floating point number.
781
    if pobyso_is_floating_point_number_sa_sa(approxErrorSa):
782
        approxErrorSo = pobyso_constant_sa_so(approxErrorSa)
783
    else:
784
        approxErrorSo = pobyso_constant_sa_so(RR(approxErrorSa))
770 785
    if not weightSa is None:
771 786
        weightAsStringSa = weightSa._assume_str()
772 787
        weightSo = pobyso_parse_string_sa_so(weightAsStringSa)
788
        if pobyso_is_error(weightSo):
789
            sollya_lib_clear_obj(functionSo)
790
            sollya_lib_clear_obj(rangeSo)
791
            sollya_lib_clear_obj(approxErrorSo)   
792
            sollya_lib_clear_obj(weightSo)
793
            return 0   
773 794
    else:
774 795
        weightSo = None
775 796
    if not degreeBoundSa is None:
......
778 799
        degreeBoundSo = None
779 800
    guessedDegreeSa = pobyso_guess_degree_so_sa(functionSo,
780 801
                                              rangeSo,
781
                                              errorSo,
802
                                              approxErrorSo,
782 803
                                              weightSo,
783 804
                                              degreeBoundSo)
784 805
    sollya_lib_clear_obj(functionSo)
785 806
    sollya_lib_clear_obj(rangeSo)
786
    sollya_lib_clear_obj(errorSo)
807
    sollya_lib_clear_obj(approxErrorSo)
787 808
    if not weightSo is None:
788 809
        sollya_lib_clear_obj(weightSo)
789 810
    if not degreeBoundSo is None:
......
851 872
    return(intervalSo)
852 873
# End pobyso_interval_to_range_sa_so
853 874

  
875
def pobyso_is_error_so_sa(objSo):
876
    """
877
    Thin wrapper around the sollya_lib_obj_is_error() function.
878
    """
879
    if sollya_lib_obj_is_error(objSo) != 0:
880
        return True
881
    else:
882
        return False
883
# End pobyso_is_error-so_sa
884

  
885
def pobyso_is_floating_point_number_sa_sa(numberSa):
886
    """
887
    Check whether a Sage number is floating point
888
    """
889
    return numberSa.parent().__class__ is RR.__class__
890

  
854 891
def pobyso_lib_init():
855 892
    sollya_lib_init(None)
856 893

  
......
873 910
 
874 911
def pobyso_parse_string_sa_so(string):
875 912
    """
876
    Get the Sollya expression computed from a Sage string.
913
    Get the Sollya expression computed from a Sage string or
914
    a Sollya error object if parsing failed.
877 915
    """
878 916
    return(sollya_lib_parse_string(string))
879 917

  

Formats disponibles : Unified diff