Changeset 7470:77fc98e0bcb8
- Timestamp:
- 12/01/07 13:15:38 (5 years ago)
- Branch:
- default
- Location:
- sage
- Files:
-
- 2 edited
-
misc/functional.py (modified) (1 diff)
-
rings/real_mpfr.pyx (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
sage/misc/functional.py
r7087 r7470 724 724 prec = 53 725 725 else: 726 prec = int( digits * 3.4) + 2726 prec = int((digits+1) * 3.32192) + 1 727 727 try: 728 728 return x.numerical_approx(prec) -
sage/rings/real_mpfr.pyx
r7452 r7470 938 938 no_sci = not (<RealField>self._parent).sci_not 939 939 940 if no_sci is True and ( -exponent > digits or exponent > 2*digits):940 if no_sci is True and ( abs(exponent-1) >=6 ): 941 941 no_sci = False 942 942 … … 947 947 948 948 lpad = '' 949 949 950 if exponent <= 0: 950 951 n = len(t) … … 952 953 else: 953 954 n = exponent 955 954 956 if t[0] == '-': 955 957 lpad = '-' + lpad … … 957 959 z = lpad + str(t[:n]) 958 960 w = t[n:] 959 if len(w) > 0: 961 962 if len(w) > 0 and '.' not in z: 960 963 z = z + ".%s"%w 961 964 elif exponent > 0: 962 z = z + '0'*(n-len(t)) 965 z = z + '0'*(n-len(t)) 963 966 if '.' not in z: 964 z = z + '.' 967 z = z + "." 968 965 969 return z 966 970 … … 2981 2985 if not isinstance(s, str): 2982 2986 s = str(s) 2983 if base == 10: 2984 bits = int(3.32192*len(s)) 2987 2988 if 'e' in s or 'E' in s: 2989 #Figure out the exponent 2990 index = max( s.find('e'), s.find('E') ) 2991 exponent = int(s[index+1:]) 2992 rest = s[:index] 2993 2994 #Find the first nonzero entry in rest 2995 sigfigs = 0 2996 for i in range(len(rest)): 2997 if rest[i] != '.' and rest[i] != '0': 2998 sigfigs = len(rest) - i 2999 break 3000 3001 if base == 10: 3002 bits = int(3.32192*sigfigs)+1 3003 else: 3004 bits = int(math.log(base,2)*sigfigs)+1 2985 3005 else: 2986 bits = int(math.log(base,2)*len(s)) 3006 #Find the first nonzero entry in s 3007 sigfigs = 0 3008 for i in range(len(s)): 3009 if s[i] != '.' and s[i] != '0': 3010 sigfigs = len(s) - i 3011 break 3012 3013 if base == 10: 3014 bits = int(3.32192*sigfigs)+1 3015 else: 3016 bits = int(math.log(base,2)*sigfigs)+1 3017 2987 3018 R = RealField(prec=max(bits+pad, min_prec), rnd=rnd) 2988 3019 return RealNumber(R, s, base)
Note: See TracChangeset
for help on using the changeset viewer.
