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


Groups > comp.lang.forth > #57597

Re: real to rational number

Newsgroups comp.lang.forth
Date 2017-04-19 05:35 -0700
References <d34926ea-ca84-4918-aa2f-82ebb21c6470@googlegroups.com> <cbb13407-c652-44c0-baba-5f6fa8682972@googlegroups.com> <342f6e4f-5413-4a41-a92a-1fd5dd35c45b@googlegroups.com> <de75f7ac-5c5e-425d-b556-9088b2838ebf@googlegroups.com>
Message-ID <737e1f6d-5288-40bb-b07e-e959bdbdcdcf@googlegroups.com> (permalink)
Subject Re: real to rational number
From Pablo Hugo Reda <pabloreda@gmail.com>

Show all headers | View raw


El miércoles, 19 de abril de 2017, 9:30:24 (UTC-3), Pablo Hugo Reda  escribió:
> El miércoles, 19 de abril de 2017, 0:05:41 (UTC-3), krishna...@ccreweb.org  escribió:
> > On Tuesday, April 18, 2017 at 9:58:24 PM UTC-5, Pablo Hugo Reda wrote:
> > ...
> > > I convert from fixed point 16.16 to fraction for a calculator
> > > 
> > > the complete lib in
> > > https://github.com/phreda4/reda4/blob/master/r4/Lib/frac.txt
> > > 
> > > the lib has 50 lines, make a fraction of decimal part symplify and sum de integer par, I guess.
> > > 
> > > 
> > > 
> > > ::gcd | n1 n2 -- gcd
> > > 	( 1? )(	swap over mod ) drop ;
> > > 
> > > ::fsimp | n1 n2 -- n1 n2
> > > 	2dup gcd 0? ( drop ; ) 
> > > 	>r r / swap r> / swap
> > > 	-? ( swap neg swap neg ) ;
> > > 
> > > ::fix2f | fix -- n1 d1
> > > 	dup 16 >> swap $10000 fsimp rot over * rot + swap ;
> > 
> > Hi Pablo,
> > 
> > Can you give me an example of using this to solve the originally stated problem?
> > 
> > Krishna
> 
> Krishna
> 
> I found a bug!,not work for number with not zero integer part, the code for test is
> 
> :main
> 	show clrscr
> 
> 		0.6190 | 7.619 not work
> 		dup "%f " print  | print fixpoint
> 		fix2f 2dup       | convert to fraction
> 		swap "%d/%d" print | print in fraction
>     	        16 <</ " %f" print | back to fixed point
> 
> 		'exit >esc<
> 		cminiflecha ;
> 
> I don't remenber how code this.
> for 0.619 work ok but for 7.619 give me 14.619, the integer part is doubled! 
> sorry.

well try this and work:

::fix2f | fix -- n1 d1
	dup 16 >> swap $ffff and $10000 fsimp rot over * rot + swap ;

clear the fractional part for make the fraction..
remenber my fixed point number are 16.16, not great precision.

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


Thread

real to rational number krishna.myneni@ccreweb.org - 2017-04-18 04:49 -0700
  Re: real to rational number lehs <skydda.barnen@gmail.com> - 2017-04-18 06:48 -0700
    Re: real to rational number krishna.myneni@ccreweb.org - 2017-04-18 19:09 -0700
      Re: real to rational number lehs <skydda.barnen@gmail.com> - 2017-04-18 22:53 -0700
        Re: real to rational number krishna.myneni@ccreweb.org - 2017-04-19 04:43 -0700
          Re: real to rational number rickman <gnuarm@gmail.com> - 2017-04-19 15:41 -0400
            Re: real to rational number Paul Rubin <no.email@nospam.invalid> - 2017-04-19 13:03 -0700
              Re: real to rational number "Rudy Velthuis" <newsgroups@rvelthuis.de> - 2017-04-20 17:26 +0000
              Re: real to rational number hughaguilar96@gmail.com - 2017-04-20 14:29 -0700
      Re: real to rational number "Rudy Velthuis" <newsgroups@rvelthuis.de> - 2017-04-19 23:44 +0000
        Re: real to rational number Paul Rubin <no.email@nospam.invalid> - 2017-04-19 19:30 -0700
          Re: real to rational number "Rudy Velthuis" <newsgroups@rvelthuis.de> - 2017-04-20 17:08 +0000
            Re: real to rational number Paul Rubin <no.email@nospam.invalid> - 2017-04-20 11:46 -0700
              Re: real to rational number "Rudy Velthuis" <newsgroups@rvelthuis.de> - 2017-04-21 09:47 +0000
            Re: real to rational number lehs <skydda.barnen@gmail.com> - 2017-04-20 20:49 -0700
    Re: real to rational number rickman <gnuarm@gmail.com> - 2017-04-19 15:36 -0400
      Re: real to rational number krishna.myneni@ccreweb.org - 2017-04-20 18:44 -0700
  Re: real to rational number hughaguilar96@gmail.com - 2017-04-18 07:06 -0700
    Re: real to rational number krishna.myneni@ccreweb.org - 2017-04-18 19:17 -0700
      Re: real to rational number Paul Rubin <no.email@nospam.invalid> - 2017-04-18 19:45 -0700
        Re: real to rational number krishna.myneni@ccreweb.org - 2017-04-18 19:57 -0700
        Re: real to rational number anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2017-04-19 05:35 +0000
      Re: real to rational number hughaguilar96@gmail.com - 2017-04-18 23:42 -0700
        Re: real to rational number krishna.myneni@ccreweb.org - 2017-04-19 04:53 -0700
          Re: real to rational number hughaguilar96@gmail.com - 2017-04-19 11:32 -0700
  Re: real to rational number minforth@arcor.de - 2017-04-18 08:23 -0700
    Re: real to rational number krishna.myneni@ccreweb.org - 2017-04-18 19:24 -0700
      Re: real to rational number Paul Rubin <no.email@nospam.invalid> - 2017-04-18 19:48 -0700
        Re: real to rational number krishna.myneni@ccreweb.org - 2017-04-18 20:01 -0700
  Re: real to rational number Paul Rubin <no.email@nospam.invalid> - 2017-04-18 19:39 -0700
    Re: real to rational number krishna.myneni@ccreweb.org - 2017-04-18 19:56 -0700
      Re: real to rational number Paul Rubin <no.email@nospam.invalid> - 2017-04-19 00:41 -0700
        Re: real to rational number krishna.myneni@ccreweb.org - 2017-04-19 04:48 -0700
        Re: real to rational number hughaguilar96@gmail.com - 2017-04-19 11:30 -0700
      Re: real to rational number albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2017-04-20 20:15 +0200
        Re: real to rational number krishna.myneni@ccreweb.org - 2017-04-20 15:23 -0700
          Re: real to rational number Paul Rubin <no.email@nospam.invalid> - 2017-04-20 18:52 -0700
  Re: real to rational number Pablo Hugo Reda <pabloreda@gmail.com> - 2017-04-18 19:58 -0700
    Re: real to rational number krishna.myneni@ccreweb.org - 2017-04-18 20:05 -0700
      Re: real to rational number Pablo Hugo Reda <pabloreda@gmail.com> - 2017-04-19 05:30 -0700
        Re: real to rational number Pablo Hugo Reda <pabloreda@gmail.com> - 2017-04-19 05:35 -0700
          Re: real to rational number Pablo Hugo Reda <pabloreda@gmail.com> - 2017-04-19 05:41 -0700
            Re: real to rational number krishna.myneni@ccreweb.org - 2017-04-19 19:39 -0700
  Re: real to rational number "Rudy Velthuis" <newsgroups@rvelthuis.de> - 2017-04-19 23:16 +0000
    Re: real to rational number krishna.myneni@ccreweb.org - 2017-04-19 19:42 -0700
      Re: real to rational number "Rudy Velthuis" <newsgroups@rvelthuis.de> - 2017-04-20 17:15 +0000
        Re: real to rational number krishna.myneni@ccreweb.org - 2017-04-20 15:11 -0700
          Re: real to rational number hughaguilar96@gmail.com - 2017-04-20 15:49 -0700
            Re: real to rational number Alex <alex@rivadpm.com> - 2017-04-21 00:20 +0100
              Re: real to rational number krishna.myneni@ccreweb.org - 2017-04-20 18:49 -0700
                Re: real to rational number The Beez <the.beez.speaks@gmail.com> - 2017-04-21 03:18 -0700
                Re: real to rational number krishna.myneni@ccreweb.org - 2017-04-21 18:39 -0700
                Re: real to rational number krishna.myneni@ccreweb.org - 2017-04-21 18:46 -0700
                Re: real to rational number Paul Rubin <no.email@nospam.invalid> - 2017-04-21 21:55 -0700
                Re: real to rational number krishna.myneni@ccreweb.org - 2017-04-22 08:33 -0700
                Re: real to rational number Paul Rubin <no.email@nospam.invalid> - 2017-04-22 13:35 -0700
                Re: real to rational number The Beez <the.beez.speaks@gmail.com> - 2017-04-24 00:58 -0700
                Re: real to rational number minforth@arcor.de - 2017-04-24 01:08 -0700
                Re: real to rational number minforth@arcor.de - 2017-04-23 02:28 -0700
                Re: real to rational number hughaguilar96@gmail.com - 2017-04-21 18:43 -0700
                rationalising  reality,   was Re: real to rational number Jan Coombs <jenfhaomndgfwutc@murmic.plus.com> - 2017-04-22 10:28 +0100
                Re: rationalising  reality,   was Re: real to rational number Mark Wills <markwills1970@gmail.com> - 2017-04-22 02:33 -0700
            Re: real to rational number krishna.myneni@ccreweb.org - 2017-04-20 16:22 -0700
              Re: real to rational number hughaguilar96@gmail.com - 2017-04-20 22:02 -0700
                Re: real to rational number Julian Fondren <julian.fondren@gmail.com> - 2017-04-21 00:12 -0700
                Re: real to rational number "Rudy Velthuis" <newsgroups@rvelthuis.de> - 2017-04-21 09:55 +0000
                Re: real to rational number hughaguilar96@gmail.com - 2017-04-25 10:52 -0700
                Re: real to rational number "Rudy Velthuis" <newsgroups@rvelthuis.de> - 2017-04-29 03:16 +0000
              Re: real to rational number "Rudy Velthuis" <newsgroups@rvelthuis.de> - 2017-04-21 09:52 +0000
              Re: real to rational number lehs <skydda.barnen@gmail.com> - 2017-04-21 05:35 -0700
                Re: real to rational number hughaguilar96@gmail.com - 2017-04-21 19:05 -0700
                Re: real to rational number The Beez <the.beez.speaks@gmail.com> - 2017-04-24 01:14 -0700
                Re: real to rational number Cecil Bayona <cbayona@cbayona.com> - 2017-04-24 11:31 -0500
                Re: real to rational number The Beez <the.beez.speaks@gmail.com> - 2017-04-25 00:52 -0700
                Re: real to rational number hughaguilar96@gmail.com - 2017-04-24 11:43 -0700
                Re: real to rational number The Beez <the.beez.speaks@gmail.com> - 2017-04-25 00:35 -0700
                Re: real to rational number The Beez <the.beez.speaks@gmail.com> - 2017-04-25 01:09 -0700
                Re: real to rational number minforth@arcor.de - 2017-04-26 01:55 -0700

csiph-web