#!/bin/sh

# #!/usr/local/bin/dash
# scicalc

# USAGE 1: All methods: [/full/path/to/|./]scicalc ['|"]expression_inside_quotes["|']<CR>
# USAGE 2: In a script: VAR='expression'; ./scicalc "${VAR}"<CR>
# Which quotes depends on the situation, "${VAR}" as an expression variable is valid '${VAR}' is invalid.

# All angular expressions are in radians!
expression="$1"

# Don't allow an empty "$1".
if [ "${expression}" = "" ]
then
	echo "Basic USAGE: [./]scicalc [']"'["]''expression_inside_quotes''["]'"[']""<CR>"
	echo "!!!Read the code for more information!!!"
	exit 1
fi

# Minimum awk Version tested on:
# GNU Awk 3.0.3.
# For the AMIGA A1200(HD) OS3.0.x, running ADE, the UNIX environment using ksh88 as the shell.
#
# Developed on OSX 10.14.x, "awk version 20070501".
awk 'BEGIN{ pi=3.141592653589793; e=2.718281828459045; printf "%.15f", ('"${expression}"'); print ""; }'

# Example 1:
# ./scicalc '(sin(pi / 3.5) * sin(pi / 3.5) + cos(pi / 3.5) * cos(pi / 3.5)) / 3.0'
# Result:
# 0.333333333333333
# Google result:
# 0.33333333333
#
# Example 2:
# ./scicalc '(123.456**(1.2/3.4))'
# Result:
# 5.472437081627787
# Google result:
# 5.47243708163
