From: Barry Margolin <barmar@alum.mit.edu>
To: help-gnu-emacs@gnu.org
Subject: Re: beginning-of-buffer computations
Date: Thu, 29 Jan 2015 17:17:16 -0500 [thread overview]
Message-ID: <barmar-B50CC9.17171629012015@88-209-239-213.giganet.hu> (raw)
In-Reply-To: mailman.18932.1422563201.1147.help-gnu-emacs@gnu.org
In article <mailman.18932.1422563201.1147.help-gnu-emacs@gnu.org>,
Marcin Borkowski <mbork@wmi.amu.edu.pl> wrote:
> Hello people,
>
> I'm continuing my journey through simple.el, and I've just found
> something strange. Apparently, a PhD in maths is not enough to grok the
> arithmetic operations in beginning-of-buffer...;-)
>
> (goto-char (if (and arg (not (consp arg)))
> (+ (point-min)
> (if (> size 10000)
> ;; Avoid overflow for large buffer sizes!
> (* (prefix-numeric-value arg)
> (/ size 10))
> (/ (+ 10 (* size (prefix-numeric-value arg))) 10)))
> (point-min)))
>
> Now I pretty much see what is going on for "large buffers". For smaller
> ones, I'm wondering what is the rationale behind the `+ 10' part? It
> approximately adds one to the result (of course, the result is truncated
> to the next-lower-integer, so it's not that, ekhm, simple) - but why?
Good question. I don't think there's any difference between that and
(+ 1 (/ (* size (prefix-numeric-value arg)) 10))
It would make more sense if it were adding 5, which would be the way to
round up.
>
> (Not to mention the next line - not shown here - which `forward-line's
> by 1. Why not just (beginning-of-line) instead?)
forward-line ignores field boundaries, beginning-of-line doesn't.
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
next parent reply other threads:[~2015-01-29 22:17 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <mailman.18932.1422563201.1147.help-gnu-emacs@gnu.org>
2015-01-29 22:17 ` Barry Margolin [this message]
2015-01-29 20:26 beginning-of-buffer computations Marcin Borkowski
2015-02-01 14:18 ` Michael Heerdegen
2015-02-01 14:42 ` Robert Thorpe
2015-02-01 14:47 ` Robert Thorpe
2015-02-01 14:52 ` Stefan Monnier
2015-02-01 15:55 ` Michael Heerdegen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=barmar-B50CC9.17171629012015@88-209-239-213.giganet.hu \
--to=barmar@alum.mit.edu \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).