man wcalc (Commandes) - a natural-expression command-line calculator
NAME
wcalc - a natural-expression command-line calculator
SYNOPSIS
wcalc [ options ] [ expression ... ]
DESCRIPTION
wcalc is a command-line calculator designed to accept all valid mathematical expressions. It supports all standard mathematical operations, parenthesis, brackets, trigonometric functions, hyperbolic trig functions, logs, and boolean operators.
If no mathematical expression is given at the commandline, wcalc enters "interactive" mode. Interactive mode has more features. Also, files may be piped to wcalc, and they will be interpreted.
Variables are supported and may be assigned using the = operator. To assign a variable use the form: foo = anylegalexpression Thereafter, that variable name is the same as the literal value it represents. Expressions can be stored in variables like this: "foo = 'anylegalexpression' Expressions stored this way will be interpreted at evaluation time, rather than assignment-time. Note that these cannot be recursive.
OPTIONS
- -H or =help
- Prints a help usage message to standard output, then exits.
- -E
- Specifies that numerical output should be in scientific notation.
- -PXXX
- Sets the precision to be XXX. This setting only affects output, not internal representations. A setting of -1 means formats output in whatever precision seems appropriate.
Precision is set to autoadjust (-1) by default.
Example: wcalc -P6 - -v or =version
- Prints the version number and exits.
- -d or -dec or =decimal
- Results are printed in decimal (base 10). This option is the default, and does not have a default prefix to indicate that numbers are in base 10.
- -h or -hex or =hexadecimal
- Results are printed in hexadecimal (base 16). Numbers printed in hexadecimal have a prefix of 0x unless the -p or =prefixes option is used.
- -o or -oct or =octal
- Results are printed in octal (base 8). Numbers printed in octal have a prefix of 0 unless the -p or =prefixes option is used.
- -b or -bin or =binary
- Results are printed in binary (base 2). Numbers printed in binary have a prefix of 0b unless the -p or =prefixes option is used.
- -p or =prefixes
- Toggles printing prefixes for hexadecimal, octal, and binary forms.
- -l or =lenient
- Makes the parser assume that uninitialized variables have a value of zero.
- -r or =radians
- Toggles whether trigonometric functions assume input (and output) is in radians. By default, trigonometric functions assume input is in degrees.
- -q or =quiet
- Toggles whether the equals sign will be printed before the results.
- -c or =conservative
- Toggles precision guards. Because of the way floating point numbers are stored, some operations, like 1-.9-.1, can return an extremely small number that is not zero but is less than the official precision of the floating point number and thus for all intents and purposes, it is 0. The precision guard will round numbers to zero if they are less than the official precision of the floating point number. However, sometimes numbers that small or smaller need to be displayed, and thus the precision guard should be turned off.
- =remember
- Toggles whether or not expressions that produce errors are remembered in the history. Does not affect command-line math.
- =round= { none | simple | sig_fig }
- Wcalc can attempt to warn you when numbers have been rounded in the output display. It has two methods of keeping track---either by using significant figures (sig_fig), or by a simple digit-counting algorithm. Rounding in the command-line version is denoted by a tilde before the equals sign (~=). Rounding in the GUI version is denoted by changing the text color to red. In some cases, Wcalc may think that the number has been rounded even if it shouldn't have been necessary (this is because of the way floating point numbers are represented internally).
- =dsep=X
- Sets the decimal separator character to be X.
- =tsep=X
- Sets the thousands separator character to be X.
- =bitsXXXX
- Sets the number of bits of precision that will be used to internally represent numbers to be XXXX. The default is 1024. Set higher if you need more precision, set lower if you want to use less memory.
- =ints
- Toggles whether long integers will be abbreviated or not. This conflicts with engineering notation for large numbers, but not for decimals.
FUNCTIONS
The functions supported in wcalc are almost all self-explanatory. For those few that are not, here is a full description.
- sin cos tan cot
- The standard trigonometric functions
- asin acos atan acot or arcsin arccos arctan arccot or sin^-1 cos^-1 tan^-1 cot^-1
- The standard arc- trigonometric functions.
- sinh cosh tanh coth
- The standard hyperbolic trigonometric functions.
- asinh acosh atanh acoth or arcsinh arccosh arctanh arccoth or sinh^-1 cosh^-1 tanh^-1 coth^-1
- The standard arc- hyperbolic trigonometric functions.
- log ln logtwo
- Log-base-ten, log-base-e and log-base-two, respectively. Remember, you can also construct log-base-X of number Y by computing log(Y)/log(X).
- round
- Returns the integral value nearest to the argument according to the typical rounding rules.
- abs
- Returns the absolute value of the argument.
- ceil ceiling floor
- Returns the ceiling or floor of the argument.
- sqrt cbrt
- The square and cube root functions.
- rand
- Returns a random number between 0 and the number given.
- irand
- Returns a random integer between 0 and the number given.
- fact
- Returns the factorial of a number.
SYMBOLS
Wcalc supports a lot of constants. Some are special (like pi), and some are simply mathematical or physical constants that have been hardcoded in. The physics constants are taken from http://physics.nist.gov/constants, and should all be in predictable SI units.
The value of pi is special, as it is calculated to however many bits of precision have been specified with the \bits command. The default number of bits is 1024, or a value of:
3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245869974724822361502823407955151120558811684656967313093357387193011055974127397801166600823447367841524950037348489795545416453901986117572722731871388422643588974212021713194956805142308399313566247553371620129340026051601856684677033122428187855479365508702723110143458240736806341798963338923286460351089772720817919599675133363110147505797173662675795471777702814318804385560929672479177350549251018537674006123614790110383192502897923367993783619310166679013187969315172579438604030363957033826325935372151289640167976948453904619615481368332936937026831888367580239969088932697527811653282224950410336573385944190516446146423694037380609059088222036945727944116946240616684848934170304346480406820774078369140625
Similarly, all values that rely on the value of pi, like mu0, have the same level of precision. Here is a complete list of the symbols used to represent the constants hardcoded into wcalc:
- e
- The logarithm constant:
2.718281828459045235360287471352662497757247093699959574966 - gamma
- Euler's Constant: 0.57721566490153286060651209008240243104215933593992359880576723488486772677766467093694706329174674951463144724980708248096050401448654283622417399764492353625350033374293733773767394279259525824709491600873520394816567
- g
- Acceleration due to gravity: 9.80665 m/s/s
- Cc
- Coulomb's Constant: 8987551787.37
Universal Constants
- Z0 or Zzero
- Impedance of Vacuum: 376.730313461 ohms
- epsilon0 or epsilonzero
- Permittivity of Free Space: 8.854187817e-12 F/m
- mu0 or muzero
- Permeability of Free Space calculated as 4*pi*10^-7.
- G
- Gravitational Constant: 6.67259e-11
- h
- Planck Constant: 6.6260755e-34
- c
- Speed of Light: 299792458
Electromagnetic Constants
- muB
- Bohr Magneton: 5.78838174943e-11 J/T
- muN
- Nuclear Magneton: 3.15245123824e-14 J/T
- G0
- Conductance Quantum: 7.748091733e-5 S
- ec
- Elementary Charge: 1.60217653e-19
- Kj
- Josephson Constant: 483597.879e9 Hz/V
- Rk
- Von Klitzing Constant: 25812.807449 omega
Atomic and Nuclear Constants
- Malpha
- Alpha Particle Mass: 6.6446565e-27 kg
- ao
- Bohr Radius: 0.5291772108e-10
- Md
- Deuteron Mass: 3.34358335e-27 kg
- Me
- Electron Mass: 9.1093897e-31 kg
- re
- Electron Radius: 2.817940325e-15 m
- eV
- Electron Volt: 1.602177250e-12 J
- Gf
- Fermi Coupling Constant: 1.16638e-5 GeV^-2
- alpha
- Fine Structure Constant: 7.29735253327e-3
- eh
- Hartree Energy: 4.35974417e-18 J
- Mh
- Helion Mass: 5.00641214e-27 kg
- Mmu
- Muon Mass: 1.88353140e-28 kg
- Mn
- Neutron Mass: 1.67492728e-27 kg
- Mp
- Proton Mass: 1.67262171e-27 kg
- Rinf
- Rydberg Constant: 10973731.568525 1/m
- Mt
- Tau Mass: 3.16777e-27 kg
Physio-Chemical Constants
- u
- Atomic Mass Constant: 1.66053886e-27 kg
- Na or NA
- Avogadro's Constant: 6.0221367e23
- k
- Boltzmann Constant: 1.3806505e-23
- F
- Faraday Constant: 96485.3383 C/mol
- c1
- First Radiation Constant: 3.74177138e-16 W m^2
- n0 or nzero
- Loschmidt Constant: 2.6867773e25 m^-3
- R
- Molar Gas Constant: 8.314472
- Vm or NAk
- Molar Volume of Ideal Gas: 22.413996e-3 (m^3)/mol
- c2
- Second Radiation Constant: 1.4387752e-2 m K
- sigma
- Stefan-Boltzmann Constant: 5.670400e-8
- b
- Wien Displacement Law Constant: 2.8977686e-3 m K
Random Constants
- random
- A Random Value
- irandom
- A Random Integer
COMMANDS
There are several commands that are supported in wcalc.
- \pXXX
- Sets the precision to XXX. This setting only affects output, not internal representations. A setting of -1 means formats output in whatever precision seems appropriate.
- \e or \eng or \engineering
- Toggles the formatting of output between decimal and scientific notation.
- \help or ?
- Displays a help screen.
- \prefs
- Prints out the current preference settings.
- \li or \list or \listvars
- Prints out the currently defined variables.
- \r or \radians
- Toggles between using and not using radians for trigonometric calculations.
- \cons or \conservative
- Toggles precision guards. Because of the way floating point numbers are stored, some operations, like 1-.9-.1, can return an extremely small number that is not zero but is less than the official precision of the floating point number and thus for all intents and purposes, it is 0. The precision guard will round numbers to zero if they are less than the official precision of the floating point number. However, sometimes numbers that small or smaller need to be displayed, and thus the precision guard should be turned off.
- \p or \picky or \l or \lenient
- Toggles variable parsing rules. When wcalc is "picky" it will complain if you use undefined variables. If it is "lenient", wcalc will assume a value of 0 for undefined variables.
- \re or \remember or \remember_errors
- Toggles whether or not expressions that produce errors are remembered in the history.
- \pre or \prefix or \prefixes
- Toggles the display of prefixes for hexadecimal, octal, and binary output.
- \b or \bin or \binary
- Results are printed in binary (base 2). Numbers printed in binary have a prefix of 0b unless the \prefixes command is used.
- \d or \dec or \decimal
- Results are printed in decimal (base 10). This option is the default, and does not have a default prefix to indicate that numbers are in base 10.
- \h or \x or \hex or \hexadecimal
- Results are printed in hexadecimal (base 16). Numbers printed in hexadecimal have a prefix of 0x unless the \prefixes command is used.
- \o or \oct or \octal
- Results are printed in octal (base 8). Numbers printed in octal have a prefix of 0 unless the \prefixes command is used.
- \round none|simple|sig_fig
- Wcalc can attempt to warn you when numbers have been rounded in the output display. It has two methods of keeping track---either by using significant figures (sig_fig), or by a simple digit-counting algorithm. Rounding in the command-line version is denoted by a tilde before the equals sign (~=). Rounding in the GUI version is denoted by changing the text color to red. In some cases, Wcalc may think that the number has been rounded even if it shouldn't have been necessary (this is because of the way floating point numbers are represented internally).
- \dsepX
- Sets the decimal separator character to be X.
- \tsepX
- Sets the thousands-place separator character to be X.
- \hlimitX
- Sets the limit (X) on the length of the history.
- \openXXXXX
- Loads file XXXXX.
- \saveXXXXX
- Saves the history and variable list to a file, XXXXX.
- \bitsXXXX
- Sets the number of bits of precision that will be used to internally represent numbers to be XXXX. The default is 1024. Set higher if you need more precision, set lower if you want to use less memory.
- \ints
- Toggles whether long integers will be abbreviated or not. This conflicts with engineering notation for large numbers, but not for decimals.
- \prefs or \preferences
- Displays the current preference settings.
- \convert unit1 unit1
- Converts the previous answer from unit1 to unit2.
COPYRIGHT
wcalc is Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005 Kyle Wheeler.
It is freely distributed, and can be modified and used freely for any purpose,
as long as a copy of the modification is sent to Kyle Wheeler at kyle-wcalc@memoryhole.net.
SUGGESTIONS AND BUG REPORTS
Any bugs found should be reported to
Kyle Wheeler at kyle-wcalc@memoryhole.net.