Question: evalf[d] and Digits

A fact that seems to be not documented. Probably it should be obvious.

 

Digits := d0
evalf[d](expr);

 

The toplevel float sub-expressions in expr  are computed with Digits=d0 but in procedures Digits is set to d.
Notice that the actual float parameters of the toplevel procedures are evalf-ed with Digits=d0.

 

restart;

g:=proc() convert(1/3., string) end:
h:=proc() 1/3. end:

Digits:=3;
evalf[10]([
  1/3. = h(),
  convert(1/3.,string) = g(),  
  fsolve(3*x=1) = add([1/3]),
  fsolve(x/3=1/9.) # 1/9. being at top level is evalf-ed with Digits=3
])

3

 

[.333 = .3333333333, ".333" = ".3333333333", .3333333333 = .3333333333, .3330000000]

(1)

 

k:=proc(x) convert(x,string) end:

kernelopts(floatPi);

true

(2)

4.+Pi;

7.14

(3)

evalf(k(1/3.+Pi));
# floatPi seems to be ignored inside actual parameters

".333+Pi"

(4)

evalf(k(4+evalf(Pi)));

"7.14"

(5)

evalf(k(4+Pi));
# 4 not being float (or "infected" by a float) is not evalf-ed

"4+Pi"

(6)

 

### (this is documented)

`evalf/h` := proc() 7.777 end:

evalf(h(1/3));

.333

(7)

evalf('h'(1/3));

7.777

(8)

 

 

Download digits.mw

(edited)

Please Wait...