slide rules
Oliver Fromme
olli at lurza.secnetix.de
Mon May 19 12:38:49 UTC 2008
Jim Capozzoli wrote:
> So, I pulled out the slide rule yesterday that's older then I am..and
> I figured out how to multiply/divide on it. Is there anybody out
> there still using slide rules for day to day math? Or does anybody
> have any interesting stories/reminiscences about slide rules? I was
> considering figuring out how to do Trig on it and then taking my Trig
> final with it. :)
Well, I own a slide rule, it's in a drawer under my desk
at home. But I have to confess that I almost never use
it, because typing "bc -l" is much faster and delivers
more accurate results.
In fact I've bound "bc -l" to an inline hotkey of my
shell's (zsh) command line editor, so the result is
inserted at the cursor position. [*]
Best regards
Oliver
[*] PS: For users of zsh, put this into your ~/.zshrc
to bind the function to Esc M.
#
# Calculate an arithmetic expression using bc(1)
# and insert the result at the cursor position.
#
user-insert-math-expression()
{
setopt localoptions extendedglob
zle -I
local X=$(
stty sane <&2
read "X?Math expression: " <&2
echo -E "$X" | bc -l 2>/dev/null
)
if [[ $? -ne 0 || -z "$X" ]]; then
zle beep;
zle -M "*** Error in math expression! ***"
else
if [[ "$X" == *.* ]]; then # Decimal point?
X="${X%%0#}" # Remove trailing zeros.
if [[ "$X" == .* ]]; then
X="0$X" # Add zero before.
fi
fi
LBUFFER="${LBUFFER}$X"
fi
}
zle -N user-insert-math-expression
bindkey '^[m' user-insert-math-expression
--
Oliver Fromme, secnetix GmbH & Co. KG, Marktplatz 29, 85567 Grafing b. M.
Handelsregister: Registergericht Muenchen, HRA 74606, Geschäftsfuehrung:
secnetix Verwaltungsgesellsch. mbH, Handelsregister: Registergericht Mün-
chen, HRB 125758, Geschäftsführer: Maik Bachmann, Olaf Erb, Ralf Gebhart
FreeBSD-Dienstleistungen, -Produkte und mehr: http://www.secnetix.de/bsd
"FreeBSD is Yoda, Linux is Luke Skywalker"
-- Daniel C. Sobral
More information about the freebsd-chat
mailing list