all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Vincent Belaïche" <vincent.b.1@hotmail.fr>
To: "andrés ramírez" <rrandresf@hotmail.com>
Cc: emacs-devel <emacs-devel@gnu.org>,
	"boruch_baum@gmx.com" <boruch_baum@gmx.com>
Subject: RE: using ses programatically (was: a ses question)
Date: Sun, 19 Nov 2023 23:24:31 +0000	[thread overview]
Message-ID: <PAXP192MB1608F05F8AF80275F28338B884B5A@PAXP192MB1608.EURP192.PROD.OUTLOOK.COM> (raw)
In-Reply-To: <PAXP192MB16082C40D983B07ECBAEDE4684B5A@PAXP192MB1608.EURP192.PROD.OUTLOOK.COM>

[-- Attachment #1: Type: text/plain, Size: 3354 bytes --]

Just to make my point more clear, with Calc you need to write '(float 12 -1) for 1.2, and use calcFunc-add instead of +, ie (apply 'calcFunc-add (ses-range N3 N6)). Also the cell printer should be math-format-value.

Note that with IEEE754 numbers ses+ is not so useful if you are using ses-range as you can delete blank by adding a ! argument, ie (apply 'ses+ (ses-range N3 N6)) is almost the same as (apply '+ (ses-range N3 N6 !)), the sole difference is that the former does the summing in revert order.

  V.
________________________________
De : Vincent Belaïche <vincent.b.1@hotmail.fr>
Envoyé : lundi 20 novembre 2023 00:18
À : andrés ramírez <rrandresf@hotmail.com>
Cc : emacs-devel <emacs-devel@gnu.org>; boruch_baum@gmx.com <boruch_baum@gmx.com>
Objet : RE: using ses programatically (was: a ses question)

Hello,

Maybe it is due to the order of summing, ses+ is defined as follows:

(defun ses+ (&rest args)
  "Compute the sum of the arguments, ignoring blanks."
  (apply #'+ (apply #'ses-delete-blanks args)))

But ses-delete-blanks will revert the order, so in the second case you sum N6 N5 N4 N3 and not N3 N4 N5 N6.

Have you tried to use in both case '+ or 'ses+, but not '+ in one case and 'ses+ in the other case.

BR,
  V.

PS : Basically you are summing IEEE 754 floating point numbers, so there are some minor rounding errors when converting form decimal to binary and vice versa, because IEEE 754 is using a 2 exponent.
If you are doing some accounting maybe it is better to use Calc fixed point numbers, so you would have interger summing and no rounding errors as Calc is using a 10 exponent.
Of course using Calc is less practical, this is one of my big todo to make SES/Calc interaction easier.

________________________________
De : andrés ramírez <rrandresf@hotmail.com>
Envoyé : dimanche 19 novembre 2023 20:24
À : Vincent Belaïche <vincent.b.1@hotmail.fr>
Cc : emacs-devel <emacs-devel@gnu.org>; boruch_baum@gmx.com <boruch_baum@gmx.com>
Objet : Re: using ses programatically (was: a ses question)

Hi. Vincent.

>>>>> "Vincent" == Vincent Belaïche <vincent.b.1@hotmail.fr> writes:


    Vincent> I attached an updated ses-setq macro.


[...]

I have just tested the last version of ses.el

And I have found a trivial difference.

When I code:
--8<---------------cut here---------------start------------->8---
      (ses-setq :: sf N7 (+ N3 N4 N5 N6))
      (setq mysum  (number-to-string (ses-cell-value 6 13)))
      (message (format "the sum: '%s'"  mysum))
--8<---------------cut here---------------end--------------->8---
the output is:
,---- [ single digit output ]
| the sum: ’192.6’
`----

But then when code is:
--8<---------------cut here---------------start------------->8---
      (ses-setq :: sf N7 (apply 'ses+ (ses-range N3 N6)))
      (setq mysum  (number-to-string (ses-cell-value 6 13)))
      (message (format "the sum: '%s'"  mysum))
--8<---------------cut here---------------end--------------->8---
the output is:
,---- [ more than one digit decimal output ]
| the sum: ’192.60000000000002’
`----

Any idea why the difference?

BTW: yesterday I have found a different issue when using keyboard
macros for copying some specific cells to different lines on another
buffer. But. Let's end this part for asking about that one.

[-- Attachment #2: Type: text/html, Size: 8433 bytes --]

  reply	other threads:[~2023-11-19 23:24 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <SJ1PR12MB6363EAEDEA36DA78E736B9DEA61EA@SJ1PR12MB6363.namprd12.prod.outlook.com>
2023-10-29 16:43 ` a ses question Vincent Belaïche
2023-10-29 21:25   ` Vincent Belaïche
2023-10-30  5:43     ` Vincent Belaïche
2023-10-30 19:03       ` andrés ramírez
2023-11-01 19:08         ` Vincent Belaïche
2023-11-01 19:23           ` Vincent Belaïche
2023-11-02 11:20             ` Vincent Belaïche
2023-11-02 11:27               ` Vincent Belaïche
2023-11-02 11:31                 ` Vincent Belaïche
2023-11-02 18:19                 ` Stefan Monnier
2023-11-03 15:54                   ` Vincent Belaïche
2023-11-03 22:13                     ` Vincent Belaïche
2023-11-04 13:46                       ` andrés ramírez
     [not found]                       ` <SJ1PR12MB636334BD471403C3F936BF25A6A4A@SJ1PR12MB6363.namprd12.prod.outlook.com>
2023-11-05 10:25                         ` using ses programatically (was: a ses question) Vincent Belaïche
2023-11-05 14:58                           ` andrés ramírez
2023-11-05 16:55                             ` Vincent Belaïche
2023-11-05 19:33                               ` andrés ramírez
2023-11-18 22:55                                 ` Vincent Belaïche
2023-11-19 19:24                                   ` andrés ramírez
2023-11-19 23:18                                     ` Vincent Belaïche
2023-11-19 23:24                                       ` Vincent Belaïche [this message]
2023-11-20  0:33                                         ` andrés ramírez
2023-12-24 11:51                                           ` Vincent Belaïche
2023-12-24 15:44                                             ` andrés ramírez
2023-12-24 21:13                                               ` Vincent Belaïche
2023-12-27 17:42                                                 ` Vincent Belaïche

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=PAXP192MB1608F05F8AF80275F28338B884B5A@PAXP192MB1608.EURP192.PROD.OUTLOOK.COM \
    --to=vincent.b.1@hotmail.fr \
    --cc=boruch_baum@gmx.com \
    --cc=emacs-devel@gnu.org \
    --cc=rrandresf@hotmail.com \
    /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.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.