[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: shell wrappers for trig and other mathematical functions



On 10/1/19 9:18 PM, Dan Hitt wrote:
On Tue, Oct 1, 2019 at 8:58 PM David Christensen <dpchrist@holgerdanske.com>
wrote:

On 10/1/19 8:32 PM, Dan Hitt wrote:
I'm half-way looking for some shell wrappers for common trig functions
like
sin, cos, exp, log, and others.

I'm aware of bc, but it seems cumbersome.

I would like to just type 'sin 1' and get the sine (of 1 radian),

Perl one-liners are an option:

2019-10-01 19:25:59 dpchrist@tinkywinky ~
$ perl -e 'print sin 1'
0.841470984807897

<snip>

Thanks so much for your reply, including the apt-cache searching part.

It does look like a way to quickly get values for sine (or any other
function in perl).

However, i would like to dispense entirely with the 'perl -e' and 'print'
part.

As others have shown, this can be done via shell aliases and/or functions.


I really would like stand-alone programs.  This would absolutely
minimize any typing,

Shell scripts are an option. I would expect the trade-off would be flexibility of each script vs. total number of scripts. It's a question of how far to take the currying.


and if the programs had a set of good conventions,
then they would provide a model for writing others if the functions i want
are not already available in perl (or other interpreter).

So, a suite of Perl, Python, etc., and/or shell scripts with a good architecture for your needs.


CPAN has a huge number of Perl library distributions. The functions you seek may already be written:

https://www.cpan.org/


Some are available as Debian packages:

2019-10-02 20:24:25 dpchrist@tinkywinky ~/sandbox/bash
$ apt-cache search perl library | wc
    491    4329   33481


If not, you can write your own functions in Perl.


And if you are ambitious, you can write your functions in C and bring them into Perl:

https://perldoc.perl.org/perlxs.html


Thanks again for the suggestion and example!! :)

YW.  :-)


David


Reply to: