home *** CD-ROM | disk | FTP | other *** search
- # This is a fully commented version of the icalc.init file that should
- # be installed in your S: directory. It is intended to provide hints and
- # tips for new users.
- #
- # This file is readable by icalc, and has the same effect at the normal
- # icalc.init file.
- #
- # ----------------------------------------------------------------------------
- #
- # Standard startup-file for icalc.
- # Updated for version 2.1. Also, you may want to include other scripts
- # (such as gamma.ic) by read command.
- #
- # MWS, July 1992.
-
- # switch off confirmation of function definitions
- silent
-
- #
- # If icalc is called from the Workbench, only the default command paths
- # are given. We can add paths using an exec command to call the CLI Path
- # command, e.g.
- #
- # exec "path bin: add"
- #
- # We could also run an editor in the backgroung on startup, e.g.
- #
- # exec "run memacs"
- #
-
- #
- # Default number base used for displaying numbers is decimal. We could
- # change that here with a call to outbase(newbase).
- #
- # Default number of significant digits displayed is 12. Use the builtin
- # prec(numsigdigits) to change this.
- #
-
-
- # function informing you how long icalc session has been running in seconds.
- # time(0) returns the system time in seconds. We use an underscore to start
- # the variable name as a convention indicating an internal purpose.
- _sessionstart = time(0)
-
- # restore ans to zero
- # the time call above set the ans 'constant' - let's restore it to zero
- 0
-
- # time(x) returns the system time less x. We set the time we started above,
- # so this declares a function telling us how long icalc has been running.
- func session() = time(_sessionstart)
-
- # simple stopwatch functions
- # along same lines as session() above
- func start() = (_start = time(0))
- func stop() = time(_start)
-
- # timer of evaluation
- # Use as e.g. timer(Sum(n=1,1000,1/sqr(n)))
- # Prints the result of its expression, and time it took to
- # evaluate the expression in seconds.
- func timer(~expr) = { local t; t = time(0); print(expr); time(t); }
-
- # A few simple time-savers
- # Examples of the simplest function definitions
- func deg(z) = DEG*z # convert radians to degrees
- func rad(z) = z/DEG # and degrees to radians
- func log(z) = ln(z)/LOG10 # base-10 logarithm
- func lg(z) = ln(z)/LOG2 # base-2 logarithm
- func logn(z,n) = ln(z)/ln(n) # base-n logarithm
- # (works with complex bases too:)
-
- # Switch bases - note adjustment of significant figures
- # Each of these functions calls another 2, using a simple 'block'
- func bin() = { outbase(2); prec(35); } # display results in binary
- func oct() = { outbase(8); prec(15); } # display results in ocal
- func dec() = { outbase(10); prec(12); } # display results in decimal
- func hex() = { outbase(16); prec(10); } # display results in hex
-
- # Inverse hyperbolic trig functions
- # These are standard formulas simply translated into icalc functions
- func asinh(z) = -i*asin(i*z)
- func acosh(z) = -i*acos(z)
- func atanh(z) = i*atan(-i*z)
-
- # Combinatorics - could be replaced with defs in gamma.ic
- # Simple use of special function Prod(). Note that _n is used.
- func fact(n) = Prod(_n=1,n,_n)
- func perm(n,r) = Prod(_n=n-r+1,n,_n)
- func comb(n,r) = perm(n,r)/fact(r) # defined in terms of
- # other user functions
-
- # miscellaneous
-
- # Fractional part of a number
- # floor() strips imaginary part and rounds real part down to an integer.
- func frac(z) = Re(z - floor(z))
-
- # Round real & imag parts
- # Shift number up, take nearest integer, shift it back down
- func round(z,places) = int(z*10^places)/10^places
-
- # Create complex number from modulus and argument
- func polar(r,theta) = r*exp(i*theta)
-
- # Create complex number from real and imaginary parts
- func complex(real,imag) = real + i*imag
-
- # Convert decimal hours to hours, mins, seconds
- # Using print() to generate three answers; the last expression in the
- # block is returned and printed when the function is called, so no need
- # for a further print() call.
- func hms(h) = { print(floor(h)); print(floor(_t = frac(h)*60)); frac(_t)*60; }
-
- # Convert hours, mins, seconds to decimal hours
- # This is the 'inverse' of hms() defined above.
- func hours(h,m,s) = h+m/60+s/3600
-
- # restore display of results, messages
- verbose
-
- #
- # ----------------------------------------------------------------------------
- #
-
- # If we had any other favourite functions we wished defined, we could
- # either declare them here or in a file called (say) S:icalc.user, and
- # then use the commands
- #
- # echo "Reading user-definitions file"
- # read "s:icalc.user"
- #
-