GNU bug report logs -
#19582
25.0.50; [PATCH] Calc: glitches with negation of units
Previous Next
Reported by: Wolfgang Jenkner <wjenkner <at> inode.at>
Date: Tue, 13 Jan 2015 14:31:02 UTC
Severity: normal
Tags: fixed, patch
Found in version 25.0.50
Done: Lars Ingebrigtsen <larsi <at> gnus.org>
Bug is archived. No further changes may be made.
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 19582 in the body.
You can then email your comments to 19582 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#19582
; Package
emacs
.
(Tue, 13 Jan 2015 14:31:20 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Wolfgang Jenkner <wjenkner <at> inode.at>
:
New bug report received and forwarded. Copy sent to
bug-gnu-emacs <at> gnu.org
.
(Tue, 13 Jan 2015 14:31:22 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Start Calc (M-x calc).
Try to convert -1m to cm. Type
'-1m<return>uc
Then Calc asks
`(The expression is unitless when simplified) Old Units:'
This is the first glitch here, but, regardless, answer the question
m<return>
Now, it asks (correctly) for new units, so type
cm<return>
This gives the surprising result `-100 m' on top of the stack.
Now, if you do the same thing with -2 instead of -1, everything works fine.
The reason is that some of the functions in calc-units.el which, in
various ways, test for the presence of units in a given (simplified)
expression forget to handle subexpressions of the form (neg <expr>).
I propose the attached patch, which also contains some modest additions
to test/automated/cl-lib-tests.el.
There's also some math-defsimplify stuff in calc-units.el which fails to
handle the neg operator, but that shouldn't give rise to mathematical
errors and will be done in another patch.
This patch is also needed for (and, in fact, was prompted by) bug#19401.
[0001-Handle-the-neg-operator-in-some-calc-units-functions.patch (text/x-diff, attachment)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#19582
; Package
emacs
.
(Tue, 13 Jan 2015 15:57:02 GMT)
Full text and
rfc822 format available.
Message #8 received at submit <at> debbugs.gnu.org (full text, mbox):
> I propose the attached patch,
Fantastic, thanks. I'll apply the patches to Calc as soon as I get to
my home computer.
But what did you mean when you wrote:
Apparently, the representation of numbers is sometimes
influenced by previous results in the same calc stack.
?
Jay
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#19582
; Package
emacs
.
(Tue, 13 Jan 2015 16:02:01 GMT)
Full text and
rfc822 format available.
Message #11 received at submit <at> debbugs.gnu.org (full text, mbox):
On Tue, Jan 13 2015, Jay Belanger wrote:
>> I propose the attached patch,
>
> Fantastic, thanks. I'll apply the patches to Calc as soon as I get to
> my home computer.
I could do this myself, actually...
> But what did you mean when you wrote:
> Apparently, the representation of numbers is sometimes
> influenced by previous results in the same calc stack.
The same calculation can return an expression where some sub-expression
is a plain integer, say 100, or the corresponding float (float 1 2).
I'll provide an explicit example.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#19582
; Package
emacs
.
(Tue, 13 Jan 2015 16:09:01 GMT)
Full text and
rfc822 format available.
Message #14 received at submit <at> debbugs.gnu.org (full text, mbox):
>> Fantastic, thanks. I'll apply the patches to Calc as soon as I get to
>> my home computer.
>
> I could do this myself, actually...
Great!
>> But what did you mean when you wrote:
>> Apparently, the representation of numbers is sometimes
>> influenced by previous results in the same calc stack.
>
> The same calculation can return an expression where some sub-expression
> is a plain integer, say 100, or the corresponding float (float 1 2).
> I'll provide an explicit example.
Okay, thanks. Since 100 and (float 1 2) aren't the same, that might be
a bug of some kind. I'm not sure that a test should indicate that they
are equal, so maybe you shouldn't put that part in yet.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#19582
; Package
emacs
.
(Tue, 13 Jan 2015 16:26:02 GMT)
Full text and
rfc822 format available.
Message #17 received at 19582 <at> debbugs.gnu.org (full text, mbox):
On Tue, Jan 13 2015, Jay Belanger wrote:
> Since 100 and (float 1 2) aren't the same, that might be a bug of some
> kind.
Sure, but
(math-equal 100 '(float 1 2)) => t
and (info "(calc) Predicates") states
-- Function: math-equal x y
Returns true if X and Y are numerically equal, either because they
are `equal', or because their difference is `zerop'. [...]
so, IIUC, mathematically, they are as equal as it gets in calc.
On the other hand, I'm not sure if calculations with (float ...)
are exact (if possible) in calc ?
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#19582
; Package
emacs
.
(Tue, 13 Jan 2015 16:36:01 GMT)
Full text and
rfc822 format available.
Message #20 received at 19582 <at> debbugs.gnu.org (full text, mbox):
>> Since 100 and (float 1 2) aren't the same, that might be a bug of some
>> kind.
>
> Sure, but
>
> (math-equal 100 '(float 1 2)) => t
>
> and (info "(calc) Predicates") states
>
> -- Function: math-equal x y
> Returns true if X and Y are numerically equal, either because they
> are `equal', or because their difference is `zerop'. [...]
>
> so, IIUC, mathematically, they are as equal as it gets in calc.
Ah, right. But the same calculations on the same objects should produce
results which are equal, not just math-equal.
> On the other hand, I'm not sure if calculations with (float ...)
> are exact (if possible) in calc ?
Calc will do the exact computations, since internally it uses base 10 to
represents floats. Of course, the user might not consider (float ...)s
to be exact.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#19582
; Package
emacs
.
(Tue, 13 Jan 2015 16:50:02 GMT)
Full text and
rfc822 format available.
Message #23 received at 19582 <at> debbugs.gnu.org (full text, mbox):
> Ah, right. But the same calculations on the same objects should produce
> results which are equal, not just math-equal.
... an example will probably clarify the issue.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#19582
; Package
emacs
.
(Tue, 13 Jan 2015 19:40:01 GMT)
Full text and
rfc822 format available.
Message #26 received at 19582 <at> debbugs.gnu.org (full text, mbox):
On Tue, Jan 13 2015, Wolfgang Jenkner wrote:
> The same calculation can return an expression where some sub-expression
> is a plain integer, say 100, or the corresponding float (float 1 2).
> I'll provide an explicit example.
So the issue seems to be this:
In emacs -Q, do `M-x calc' then convert, say 1m, to cm, i.e.,
' 1 m <return> u c c m <return>
This gives `100 cm' on top of the stack (a plain integer scalar).
Next, start another emacs -Q instance, do `M-x calc' and then, before
anything else, `M-: (load-library "calc-units")'.
Now the same conversion exercise as before gives `100. cm' on the stack
instead (a calc float).
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#19582
; Package
emacs
.
(Tue, 13 Jan 2015 21:59:01 GMT)
Full text and
rfc822 format available.
Message #29 received at 19582 <at> debbugs.gnu.org (full text, mbox):
> So the issue seems to be this:
>
> In emacs -Q, do `M-x calc' then convert, say 1m, to cm, i.e.,
>
> ' 1 m <return> u c c m <return>
>
> This gives `100 cm' on top of the stack (a plain integer scalar).
>
> Next, start another emacs -Q instance, do `M-x calc' and then, before
> anything else, `M-: (load-library "calc-units")'.
>
> Now the same conversion exercise as before gives `100. cm' on the stack
> instead (a calc float).
Huh.
Thanks.
Well, now I see what you need to use math-equal.
As for the float, I'll see if I can fix that before the next release.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#19582
; Package
emacs
.
(Thu, 15 Jan 2015 23:56:02 GMT)
Full text and
rfc822 format available.
Message #32 received at 19582 <at> debbugs.gnu.org (full text, mbox):
On Tue, Jan 13 2015, Jay Belanger wrote:
>>> Fantastic, thanks. I'll apply the patches to Calc as soon as I get to
>>> my home computer.
>>
>> I could do this myself, actually...
>
> Great!
I've committed this now. I only corrected the comment before
calc-tests-equal in test/automated/calc-tests.el.
Since I'm working on making the simplification functions in calc-units
aware of the (neg ...) expressions where needed, I'd like to keep this
bug report open a bit longer so that I can send here the patch for
review.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#19582
; Package
emacs
.
(Sun, 18 Jan 2015 16:31:01 GMT)
Full text and
rfc822 format available.
Message #35 received at 19582 <at> debbugs.gnu.org (full text, mbox):
On Fri, Jan 16 2015, Wolfgang Jenkner wrote:
> I've committed this now.
...to master as
commit 2290000ed69b1157739c280f090e5b60112e83fe
Author: Wolfgang Jenkner <wjenkner <at> inode.at>
Date: Thu Jan 15 20:02:17 2015 +0100
Handle the `neg' operator in some calc-units functions.
However, according to
http://permalink.gmane.org/gmane.emacs.devel/181383
it falls within the category of things that should go into emacs-24
instead, so I guess I should backport it.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#19582
; Package
emacs
.
(Wed, 28 Jan 2015 15:13:02 GMT)
Full text and
rfc822 format available.
Message #38 received at 19582 <at> debbugs.gnu.org (full text, mbox):
> So the issue seems to be this:
>
> In emacs -Q, do `M-x calc' then convert, say 1m, to cm, i.e.,
>
> ' 1 m <return> u c c m <return>
>
> This gives `100 cm' on top of the stack (a plain integer scalar).
>
> Next, start another emacs -Q instance, do `M-x calc' and then, before
> anything else, `M-: (load-library "calc-units")'.
>
> Now the same conversion exercise as before gives `100. cm' on the stack
> instead (a calc float).
This is easy enough to fix, but loading error occurs when the libraries
are loaded out of order; that shouldn't be done.
When Calc is used properly, getting `100. m' instead of `100 m' would be a
bug.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#19582
; Package
emacs
.
(Tue, 23 Feb 2016 11:25:02 GMT)
Full text and
rfc822 format available.
Message #41 received at 19582 <at> debbugs.gnu.org (full text, mbox):
Wolfgang Jenkner <wjenkner <at> inode.at> writes:
> Since I'm working on making the simplification functions in calc-units
> aware of the (neg ...) expressions where needed, I'd like to keep this
> bug report open a bit longer so that I can send here the patch for
> review.
That was a year ago... I'm assuming this was fixed by now?
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
Added tag(s) fixed.
Request was from
Lars Ingebrigtsen <larsi <at> gnus.org>
to
control <at> debbugs.gnu.org
.
(Wed, 24 Feb 2016 00:46:02 GMT)
Full text and
rfc822 format available.
bug closed, send any further explanations to
19582 <at> debbugs.gnu.org and Wolfgang Jenkner <wjenkner <at> inode.at>
Request was from
Lars Ingebrigtsen <larsi <at> gnus.org>
to
control <at> debbugs.gnu.org
.
(Wed, 24 Feb 2016 00:46:02 GMT)
Full text and
rfc822 format available.
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Wed, 23 Mar 2016 11:24:07 GMT)
Full text and
rfc822 format available.
This bug report was last modified 9 years and 86 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.