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: <monnier@iro.umontreal.ca>
Cc: cyd@stupidchicken.com, emacs-devel <emacs-devel@gnu.org>
Subject: RE: Code for converting between Elisp and Calc floats
Date: Tue, 27 Oct 2009 05:56:50 +0100	[thread overview]
Message-ID: <BLU104-W109BFD7C264619CEFBFC9184B90@phx.gbl> (raw)

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














Hello Stefan,


> [SNIP]

> 
> I understand the code is simpler on the Lisp side, but I'm more
> concerned about the C side.  Of course, if the Lisp side becomes
> unmanageable it's also relevant.
>

For the C code anyhow, even if the integer component word size was not passed along in the interface, you would have anyhow to manage strange word sizes. This is because the mantissa is 53 bits, and 53 is not a multiple of 16. Also the mantissa is not aligned on the double word boundary (the sign + exponent not being a muliple of 16 bits) and
you also have this phantom bit case to handle.

I agree however that the C could have been slightly simpler if the integer component word size was forced to be 16bits.

Maybe we could add one more layer in Lisp that would encapsulate the C function and add the word lengths to be 16 for those who would like to use the builtin function for other purpose, but with a simpler interface. This would basically achieve the interface that you envisionned as far as I can understand. Calc would however not use this additional layer of code.


> [SNIP] 
> > This is the switch between the two types of implementations: the one
> > using builtin support, and the one not needing builtin support.
> 
> So (fboundp 'construct-float) would work as well?
>

Yes, definitely. That could be done this way, the  reason why I used a specific variable is more historical than rational.


> [SNIP] 
> I think it fits better in C. Basically, it would be the equivalent to
> C's frexp.

C++' frexp and ldexp are not a direct alternative, because the significand is still a non integer number (between 0.5 and 1 for frexp). So anyhow you would have to build clean powers of two to convert from the frexp returned significand to Calc internal mantissa that is an integer. Also the dynamic of the mantissa is higher than that of a Lisp integer, so any how you have so stick/split bits together/apart. However by combining calls to frexp, ldexp and floor one could get around.


Frankly speaking, I must admit that I ignored the existance of frexp and ldexp standard functions. If I had known about them, maybe I would have tried to write the builtin functions with using only frexp ldexp and stuff like _isnan and suhclikes to handle special cases. That would have come at the cost of a slight additional processing cost, but this is completely neglectable in the case of Calc, due to the overhead of Lisp.

Another alternative would be that frexp and ldexp and suhlikes are made builtin functions, and that the construct-float, deconstruct-float functions are in Lisp using those builtins: that would indeed be my preference if everyone thinks that the submitted C code is too complex. 


I am not sure however that re-coding those functions with frexp, ldexp and floor, would be that significantly less complex to justify the effort, now that I have already done the job in a more primitive way.

     Vincent.



 		 	   		  
_________________________________________________________________
Nouveau ! Tout Windows débarque dans votre téléphone. Voir les Windows phone
http://clk.atdmt.com/FRM/go/175819071/direct/01/

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

             reply	other threads:[~2009-10-27  4:56 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-27  4:56 Vincent Belaïche [this message]
2009-10-27  6:16 ` Code for converting between Elisp and Calc floats Stefan Monnier
2009-10-27 19:38   ` Vincent Belaïche
  -- strict thread matches above, loose matches on Subject: below --
2009-10-08 20:47 allow C-x v i / C-x v v to create a repository if none is available Dan Nicolaescu
2009-10-09 19:18 ` Stefan Monnier
2009-10-22 18:56   ` Code for converting between Elisp and Calc floats Jay Belanger
2009-10-22 20:04     ` James Cloos
2009-10-23  0:50     ` Stefan Monnier
2009-10-24 20:03       ` Jay Belanger
2009-10-25  0:56         ` Stefan Monnier
2009-10-25  5:36           ` David Kastrup
2009-10-25 11:36             ` Vincent Belaïche
2009-10-25 14:11               ` Chong Yidong
2009-10-25 19:29                 ` Vincent Belaïche
2009-10-26  2:30                   ` Stefan Monnier
2009-10-26 12:48                     ` Vincent Belaïche
2009-10-27  3:22                       ` Stefan Monnier
2009-10-25 13:57             ` Stefan Monnier
2009-10-25 18:35               ` Eli Zaretskii
2009-10-23 13:11     ` Richard Stallman
2009-10-23 13:26       ` David Kastrup
2009-10-24 17:34         ` Richard Stallman

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=BLU104-W109BFD7C264619CEFBFC9184B90@phx.gbl \
    --to=vincent.b.1@hotmail.fr \
    --cc=cyd@stupidchicken.com \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /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.