Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 19 May 2008 14:38:47 +0200 (CEST)
From:      Oliver Fromme <olli@lurza.secnetix.de>
To:        freebsd-chat@FreeBSD.ORG, saltmiser@gmail.com
Subject:   Re: slide rules
Message-ID:  <200805191238.m4JCclFX099026@lurza.secnetix.de>
In-Reply-To: <37f72b1f0805181418j16efd60fge243160dbfdc6789@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200805191238.m4JCclFX099026>