Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.forth > #38980

Re: How to convert whole numbers to floating?

From anton@mips.complang.tuwien.ac.at (Anton Ertl)
Newsgroups comp.lang.forth
Subject Re: How to convert whole numbers to floating?
Date 2015-05-11 16:55 +0000
Organization Institut fuer Computersprachen, Technische Universitaet Wien
Message-ID <2015May11.185535@mips.complang.tuwien.ac.at> (permalink)
References <765d92cc-590c-4da4-a0af-65f9116fbf52@googlegroups.com>

Show all headers | View raw


beeflo <beeflobill@gmail.com> writes:
>I'm struggling to understand how conversion between the parameter stack and the floating stack works, using gforth.
>
>Right now, I'm just trying to convert whole numbers (from a loop index) to the floating stack.
>
>Through experimentation I've come up with a solution:
>
>: convert (u u -- ) F:( -- r ) dup 0 < if -1 else 0 then d>f ;
>
>However, I don't really understand it.
>
>Why do negative numbers require the -1 to be passed instead of 0?  What does the top stack item mean to d>f?

It's the most significant cell of the double-cell integer d.  You can
do what you did with "dup 0 < if -1 else 0 then" with S>D.  And there
is also S>F ( n -- r ).

I apologize for not documenting S>F; now fixed in the development
version.  Thanks for reporting that bug.

- anton
-- 
M. Anton Ertl  http://www.complang.tuwien.ac.at/anton/home.html
comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html
     New standard: http://www.forth200x.org/forth200x.html
   EuroForth 2015: http://www.mpeforth.com/euroforth2015/euroforth2015.htm

Back to comp.lang.forth | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

How to convert whole numbers to floating? beeflo <beeflobill@gmail.com> - 2015-05-11 08:20 -0700
  Re: How to convert whole numbers to floating? Paul Rubin <no.email@nospam.invalid> - 2015-05-11 08:28 -0700
    Re: How to convert whole numbers to floating? beeflo <beeflobill@gmail.com> - 2015-05-11 08:57 -0700
      Re: How to convert whole numbers to floating? krishna.myneni@ccreweb.org - 2015-05-12 16:36 -0700
        Re: How to convert whole numbers to floating? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-05-13 16:04 +0000
          Re: How to convert whole numbers to floating? krishna.myneni@ccreweb.org - 2015-05-14 18:41 -0700
            Re: How to convert whole numbers to floating? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-05-15 07:23 +0000
  Re: How to convert whole numbers to floating? Coos Haak <chforth@hccnet.nl> - 2015-05-11 17:43 +0200
    Re: How to convert whole numbers to floating? beeflo <beeflobill@gmail.com> - 2015-05-11 08:58 -0700
      Re: How to convert whole numbers to floating? rickman <gnuarm@gmail.com> - 2015-05-11 15:09 -0400
  Re: How to convert whole numbers to floating? hughaguilar96@gmail.com - 2015-05-11 09:21 -0700
  Re: How to convert whole numbers to floating? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-05-11 16:55 +0000

csiph-web