Search code examples
paripari-gp

locally setting series precision -- pari-gp


everyone. This is another quick question about pari-gp.

I've written my main file such that two different functions work better if \ps 100 or \ps 36; and so I want to specify to some functions, before running, so that locally we can say \ps 100 or \ps 36.

By this I want a function with similar functionality as localprec--but with series precision as opposed to digit precision. This would mean we could have something like this,

\ps 100
/*....a bunch of code here....*/

my_local_function(var) = {
    localserprec(36); /*sets local series precision to 36, only for this function*/
    
    /*bunch of code here....*/
}

The 100 series precision functions never interact with the 36 series precision functions except when dropping down to 36. We never try to go from 36 to 100, so there should be no real problem.

Any help or comments is greatly appreciated.


Solution

  • If I understand your question correctly, you want something like this:

    my_local_function(var, {d=36}) = {
        my(old_precision = default(seriesprecision));
        default(seriesprecision, d);
    
        /* bunch of your code here.... */
    
        default(seriesprecision, old_precision);    
    }
    

    This will set d as the series precision locally applying only to your function body as you expected.