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


Groups > comp.sys.apple2.programmer > #3501 > unrolled thread

Approximating the fractional part of a FIXED number as a decimal value

Started byLuigi Thirty <luigi30@gmail.com>
First post2017-05-27 15:59 -0700
Last post2017-06-30 09:32 -0700
Articles 16 — 7 participants

Back to article view | Back to comp.sys.apple2.programmer


Contents

  Approximating the fractional part of a FIXED number as a decimal value Luigi Thirty <luigi30@gmail.com> - 2017-05-27 15:59 -0700
    Re: Approximating the fractional part of a FIXED number as a decimal value James Davis <JPD.Enterprises@live.com> - 2017-05-27 16:48 -0700
      Re: Approximating the fractional part of a FIXED number as a decimal value Luigi Thirty <luigi30@gmail.com> - 2017-05-27 18:13 -0700
        Re: Approximating the fractional part of a FIXED number as a decimal value James Davis <JPD.Enterprises@live.com> - 2017-05-27 18:48 -0700
          Re: Approximating the fractional part of a FIXED number as a decimal value Luigi Thirty <luigi30@gmail.com> - 2017-05-27 19:32 -0700
            Re: Approximating the fractional part of a FIXED number as a decimal value James Davis <JPD.Enterprises@live.com> - 2017-05-27 23:55 -0700
            Re: Approximating the fractional part of a FIXED number as a decimal value James Davis <JPD.Enterprises@live.com> - 2017-05-28 00:14 -0700
              Re: Approximating the fractional part of a FIXED number as a decimal value Kelvin Sherlock <email@domain.com> - 2017-05-28 13:52 -0400
    Re: Approximating the fractional part of a FIXED number as a decimal value John Brooks <jbrooks@blueshiftinc.com> - 2017-05-27 20:22 -0700
      Re: Approximating the fractional part of a FIXED number as a decimal value Michael Pohoreski <michael.pohoreski@gmail.com> - 2017-05-28 08:39 -0700
        Re: Approximating the fractional part of a FIXED number as a decimal value Michael Pohoreski <michael.pohoreski@gmail.com> - 2017-05-28 10:47 -0700
    Re: Approximating the fractional part of a FIXED number as a decimal value roger.shimada@gmail.com - 2017-05-28 09:10 -0700
    Re: Approximating the fractional part of a FIXED number as a decimal value Luigi Thirty <luigi30@gmail.com> - 2017-05-29 14:12 -0700
      Re: Approximating the fractional part of a FIXED number as a decimal value Michael Pohoreski <michael.pohoreski@gmail.com> - 2017-06-11 07:46 -0700
        Re: Approximating the fractional part of a FIXED number as a decimal value Michael J. Mahon <mjmahon@aol.com> - 2017-06-11 10:33 -0500
          Re: Approximating the fractional part of a FIXED number as a decimal value Michael Pohoreski <michael.pohoreski@gmail.com> - 2017-06-30 09:32 -0700

#3501 — Approximating the fractional part of a FIXED number as a decimal value

FromLuigi Thirty <luigi30@gmail.com>
Date2017-05-27 15:59 -0700
SubjectApproximating the fractional part of a FIXED number as a decimal value
Message-ID<af8abe75-cb40-4458-85f3-6b6406c2d1ed@googlegroups.com>
I'm doing some fixed-point math in my GS program and I'd like to be able to dump variables to the screen. I'm using the Integer Math Tool Set to do my calculations.

For example, I want to print the result of 100 * cos(45) and 16 bits of accuracy is enough. I can calculate it with the Integer tools...

~FracCos R_45_degrees
PullLong fixed_operand_1                   ; fixed_operand_1 = FRAC, .7854 radians
~Frac2Fix fixed_operand_1                  ; convert that to FIXED
PullLong fixed_operand_1                   ; and pull it into the operand
~FixMul fixed_operand_1;fixed_operand_2    ; fixed_operand_2 = 100.0
PullLong fixed_result                      ; 70.7106 or so

...and then print the decimal part.

~Int2Dec fixed_result+2;#str_output;#16;#1 ; signed value, 16-character string
DrawString #str_output;#0;#0               ; my function

But the fractional value held in the word at fixed_result isn't decimal, it represents 1/65536, so I can't directly print it. I don't see a conversion in the Integer Tool Set that would allow me to print it, either. Is there a built-in call for approximating the fraction word of FIXED numbers in decimal form?

[toc] | [next] | [standalone]


#3502

FromJames Davis <JPD.Enterprises@live.com>
Date2017-05-27 16:48 -0700
Message-ID<2ff480a0-ca6e-44ee-8b78-f07c27902af0@googlegroups.com>
In reply to#3501
Hi Luigi,

On Saturday, May 27, 2017 at 3:59:38 PM UTC-7, Luigi Thirty wrote:
> I'm doing some fixed-point math in my GS program and I'd like to be able to dump variables to the screen. I'm using the Integer Math Tool Set to do my calculations.
> 
> For example, I want to print the result of 100 * cos(45) and 16 bits of accuracy is enough. I can calculate it with the Integer tools...
> 
> ~FracCos R_45_degrees
> PullLong fixed_operand_1                   ; fixed_operand_1 = FRAC, .7854 radians
> ~Frac2Fix fixed_operand_1                  ; convert that to FIXED
> PullLong fixed_operand_1                   ; and pull it into the operand
> ~FixMul fixed_operand_1;fixed_operand_2    ; fixed_operand_2 = 100.0
> PullLong fixed_result                      ; 70.7106 or so
> 
> ...and then print the decimal part.
> 
> ~Int2Dec fixed_result+2;#str_output;#16;#1 ; signed value, 16-character string
> DrawString #str_output;#0;#0               ; my function
> 
> But the fractional value held in the word at fixed_result isn't decimal, it represents 1/65536, so I can't directly print it. I don't see a conversion in the Integer Tool Set that would allow me to print it, either. Is there a built-in call for approximating the fraction word of FIXED numbers in decimal form?

Modulo Arithmatic: M = Modulus, V = Value
  Quotient  = INT(V/M)
  Remainder = V-INT(V/M)*M

Use Floating Point, not Integer, routines.

James Davis

[toc] | [prev] | [next] | [standalone]


#3503

FromLuigi Thirty <luigi30@gmail.com>
Date2017-05-27 18:13 -0700
Message-ID<046b67b7-5ace-43d8-bde8-9cb6c4fcbdaf@googlegroups.com>
In reply to#3502
On Saturday, May 27, 2017 at 7:48:02 PM UTC-4, James Davis wrote:
> Hi Luigi,
> 
> On Saturday, May 27, 2017 at 3:59:38 PM UTC-7, Luigi Thirty wrote:
> > I'm doing some fixed-point math in my GS program and I'd like to be able to dump variables to the screen. I'm using the Integer Math Tool Set to do my calculations.
> > 
> > For example, I want to print the result of 100 * cos(45) and 16 bits of accuracy is enough. I can calculate it with the Integer tools...
> > 
> > ~FracCos R_45_degrees
> > PullLong fixed_operand_1                   ; fixed_operand_1 = FRAC, .7854 radians
> > ~Frac2Fix fixed_operand_1                  ; convert that to FIXED
> > PullLong fixed_operand_1                   ; and pull it into the operand
> > ~FixMul fixed_operand_1;fixed_operand_2    ; fixed_operand_2 = 100.0
> > PullLong fixed_result                      ; 70.7106 or so
> > 
> > ...and then print the decimal part.
> > 
> > ~Int2Dec fixed_result+2;#str_output;#16;#1 ; signed value, 16-character string
> > DrawString #str_output;#0;#0               ; my function
> > 
> > But the fractional value held in the word at fixed_result isn't decimal, it represents 1/65536, so I can't directly print it. I don't see a conversion in the Integer Tool Set that would allow me to print it, either. Is there a built-in call for approximating the fraction word of FIXED numbers in decimal form?
> 
> Modulo Arithmatic: M = Modulus, V = Value
>   Quotient  = INT(V/M)
>   Remainder = V-INT(V/M)*M
> 
> Use Floating Point, not Integer, routines.
> 
> James Davis

I'm sorry, I'm not sure what you mean.

[toc] | [prev] | [next] | [standalone]


#3504

FromJames Davis <JPD.Enterprises@live.com>
Date2017-05-27 18:48 -0700
Message-ID<f8408e22-f88a-47ec-b00f-143365397dc9@googlegroups.com>
In reply to#3503
Hi Luigi,

On Saturday, May 27, 2017 at 6:13:35 PM UTC-7, Luigi Thirty wrote:
> On Saturday, May 27, 2017 at 7:48:02 PM UTC-4, James Davis wrote:
> > Hi Luigi,
> > 
> > On Saturday, May 27, 2017 at 3:59:38 PM UTC-7, Luigi Thirty wrote:
> > > I'm doing some fixed-point math in my GS program and I'd like to be able to dump variables to the screen. I'm using the Integer Math Tool Set to do my calculations.
> > > 
> > > For example, I want to print the result of 100 * cos(45) and 16 bits of accuracy is enough. I can calculate it with the Integer tools...
> > > 
> > > ~FracCos R_45_degrees
> > > PullLong fixed_operand_1                   ; fixed_operand_1 = FRAC, .7854 radians
> > > ~Frac2Fix fixed_operand_1                  ; convert that to FIXED
> > > PullLong fixed_operand_1                   ; and pull it into the operand
> > > ~FixMul fixed_operand_1;fixed_operand_2    ; fixed_operand_2 = 100.0
> > > PullLong fixed_result                      ; 70.7106 or so
> > > 
> > > ...and then print the decimal part.
> > > 
> > > ~Int2Dec fixed_result+2;#str_output;#16;#1 ; signed value, 16-character string
> > > DrawString #str_output;#0;#0               ; my function
> > > 
> > > But the fractional value held in the word at fixed_result isn't decimal, it represents 1/65536, so I can't directly print it. I don't see a conversion in the Integer Tool Set that would allow me to print it, either. Is there a built-in call for approximating the fraction word of FIXED numbers in decimal form?
> > 
> > Modulo Arithmatic: M = Modulus, V = Value
> >   Quotient  = INT(V/M)
> >   Remainder = V-INT(V/M)*M
> > 
> > Use Floating Point, not Integer, routines.
> > 
> > James Davis
> 
> I'm sorry, I'm not sure what you mean.

Use the Applesoft (Floating-Point BASIC) routine to PRINT 1/65535.  It will give you a result in Scientific Notation (e.g., 1/65535 = 1.52590219E-05).  If you PRINT .0000152590219, it will give you the same result.

There has to be a way for you to transfer the value from the GS Integer Math Tool Set to the Applesoft Floating-Point routine to do the division and get a result like those above.  You can probably convert the SN to regular decimal, too.  

Does the GS have a FP Math Tool Set that you can use (instead of Applesoft), also?  

Just an IDEA!

James Davis

[toc] | [prev] | [next] | [standalone]


#3505

FromLuigi Thirty <luigi30@gmail.com>
Date2017-05-27 19:32 -0700
Message-ID<c62c15ce-0187-4d0c-b953-3d30ed398868@googlegroups.com>
In reply to#3504
On Saturday, May 27, 2017 at 9:48:50 PM UTC-4, James Davis wrote:
> Hi Luigi,
> 
> On Saturday, May 27, 2017 at 6:13:35 PM UTC-7, Luigi Thirty wrote:
> > On Saturday, May 27, 2017 at 7:48:02 PM UTC-4, James Davis wrote:
> > > Hi Luigi,
> > > 
> > > On Saturday, May 27, 2017 at 3:59:38 PM UTC-7, Luigi Thirty wrote:
> > > > I'm doing some fixed-point math in my GS program and I'd like to be able to dump variables to the screen. I'm using the Integer Math Tool Set to do my calculations.
> > > > 
> > > > For example, I want to print the result of 100 * cos(45) and 16 bits of accuracy is enough. I can calculate it with the Integer tools...
> > > > 
> > > > ~FracCos R_45_degrees
> > > > PullLong fixed_operand_1                   ; fixed_operand_1 = FRAC, .7854 radians
> > > > ~Frac2Fix fixed_operand_1                  ; convert that to FIXED
> > > > PullLong fixed_operand_1                   ; and pull it into the operand
> > > > ~FixMul fixed_operand_1;fixed_operand_2    ; fixed_operand_2 = 100.0
> > > > PullLong fixed_result                      ; 70.7106 or so
> > > > 
> > > > ...and then print the decimal part.
> > > > 
> > > > ~Int2Dec fixed_result+2;#str_output;#16;#1 ; signed value, 16-character string
> > > > DrawString #str_output;#0;#0               ; my function
> > > > 
> > > > But the fractional value held in the word at fixed_result isn't decimal, it represents 1/65536, so I can't directly print it. I don't see a conversion in the Integer Tool Set that would allow me to print it, either. Is there a built-in call for approximating the fraction word of FIXED numbers in decimal form?
> > > 
> > > Modulo Arithmatic: M = Modulus, V = Value
> > >   Quotient  = INT(V/M)
> > >   Remainder = V-INT(V/M)*M
> > > 
> > > Use Floating Point, not Integer, routines.
> > > 
> > > James Davis
> > 
> > I'm sorry, I'm not sure what you mean.
> 
> Use the Applesoft (Floating-Point BASIC) routine to PRINT 1/65535.  It will give you a result in Scientific Notation (e.g., 1/65535 = 1.52590219E-05).  If you PRINT .0000152590219, it will give you the same result.
> 
> There has to be a way for you to transfer the value from the GS Integer Math Tool Set to the Applesoft Floating-Point routine to do the division and get a result like those above.  You can probably convert the SN to regular decimal, too.  
> 
> Does the GS have a FP Math Tool Set that you can use (instead of Applesoft), also?  
> 
> Just an IDEA!
> 
> James Davis

Yeah, the GS comes with SANE in ROM. The Toolbox Reference manual says to see the Apple Numerics Manual, Second Edition for info on its function calls but I can't find a copy of the second edition manual.

[toc] | [prev] | [next] | [standalone]


#3507

FromJames Davis <JPD.Enterprises@live.com>
Date2017-05-27 23:55 -0700
Message-ID<701866ec-b8eb-4009-99d0-465c5110f9e3@googlegroups.com>
In reply to#3505
Hi Luigi,

On Saturday, May 27, 2017 at 7:32:20 PM UTC-7, Luigi Thirty wrote:
> Yeah, the GS comes with SANE in ROM. The Toolbox Reference manual says to see the Apple Numerics Manual, Second Edition for info on its function calls but I can't find a copy of the second edition manual.

I don't know if these are what you need, the second edition, but these are Apple Numerics references to downloads on Asimov and the A2 Docs Project:

ftp://public.asimov.net/pub/apple_II/documentation/programming/misc/Standard Apple Numerics Environment Manual.pdf
ftp://public.asimov.net/pub/apple_II/documentation/programming/misc/Apple Numerics Manual.pdf
ftp://public.asimov.net/pub/apple_II/documentation/programming/misc/Standard Apple Numerics Environment.txt

http://mirrors.apple2.org.za/Apple II Documentation Project/Software/Applications/SANE/Manuals/Standard Apple Numerics Environment Manual.pdf
http://mirrors.apple2.org.za/Apple II Documentation Project/Software/Applications/SANE/Manuals/Standard Apple Numerics Environment.txt

James Davis

[toc] | [prev] | [next] | [standalone]


#3508

FromJames Davis <JPD.Enterprises@live.com>
Date2017-05-28 00:14 -0700
Message-ID<3180aa33-6ad0-4f8c-9efa-46015fd2c67e@googlegroups.com>
In reply to#3505
Hi Luigi, 

On Saturday, May 27, 2017 at 7:32:20 PM UTC-7, Luigi Thirty wrote: 
> Yeah, the GS comes with SANE in ROM. The Toolbox Reference manual says to see the Apple Numerics Manual, Second Edition for info on its function calls but I can't find a copy of the second edition manual. 

I don't know if these are what you need, the second edition, but these are references to Apple Numerics downloads on Asimov and on the Apple II Documentation Project: 

ftp://public.asimov.net/pub/apple_II/documentation/programming/misc/Apple Numerics Manual.pdf 
ftp://public.asimov.net/pub/apple_II/documentation/programming/misc/SANE.PDF
ftp://public.asimov.net/pub/apple_II/documentation/programming/misc/Standard Apple Numerics Environment Manual.pdf 
ftp://public.asimov.net/pub/apple_II/documentation/programming/misc/Standard Apple Numerics Environment.txt 

ftp://public.asimov.net/pub/apple_II/images/programming/misc/Floating_Point_Engine.zip
ftp://public.asimov.net/pub/apple_II/images/programming/misc/SANE Disk 1.po
ftp://public.asimov.net/pub/apple_II/images/programming/misc/SANE Disk 2.po
ftp://public.asimov.net/pub/apple_II/images/programming/misc/SANE Disk 3.po
ftp://public.asimov.net/pub/apple_II/images/programming/misc/SANE1.do
ftp://public.asimov.net/pub/apple_II/images/programming/misc/SANE1.SHK
ftp://public.asimov.net/pub/apple_II/images/programming/misc/SANE2.do
ftp://public.asimov.net/pub/apple_II/images/programming/misc/SANE2.SHK
ftp://public.asimov.net/pub/apple_II/images/programming/misc/SANE3.do
ftp://public.asimov.net/pub/apple_II/images/programming/misc/SANE3.SHK

http://mirrors.apple2.org.za/Apple II Documentation Project/Software/Applications/SANE/
http://mirrors.apple2.org.za/Apple II Documentation Project/Software/Applications/SANE/Disk Images/
http://mirrors.apple2.org.za/Apple II Documentation Project/Software/Applications/SANE/Disk Images/SANE Disk 1.po
http://mirrors.apple2.org.za/Apple II Documentation Project/Software/Applications/SANE/Disk Images/SANE Disk 2.po
http://mirrors.apple2.org.za/Apple II Documentation Project/Software/Applications/SANE/Disk Images/SANE Disk 3.po
http://mirrors.apple2.org.za/Apple II Documentation Project/Software/Applications/SANE/Manuals/
http://mirrors.apple2.org.za/Apple II Documentation Project/Software/Applications/SANE/Manuals/Standard Apple Numerics Environment Manual.pdf
http://mirrors.apple2.org.za/Apple II Documentation Project/Software/Applications/SANE/Manuals/Standard Apple Numerics Environment.txt

James Davis

[toc] | [prev] | [next] | [standalone]


#3512

FromKelvin Sherlock <email@domain.com>
Date2017-05-28 13:52 -0400
Message-ID<ogf2i1$lbu$1@dont-email.me>
In reply to#3508
On 2017-05-28 07:14:50 +0000, James Davis said:

> Hi Luigi,
> 
> On Saturday, May 27, 2017 at 7:32:20 PM UTC-7, Luigi Thirty wrote:
>> Yeah, the GS comes with SANE in ROM. The Toolbox Reference manual says 
>> to see the Apple Numerics Manual, Second Edition for info on its 
>> function calls but I can't find a copy of the second edition manual.
> 
> I don't know if these are what you need, the second edition, but these 
> are references to Apple Numerics downloads on Asimov and on the Apple 
> II Documentation Project:

That's the first edition and only covers the 6502 and 68000 SANE 
implementations. The Second edition  also detailed the IIgs/65816 
implementation.  You can buy a used copy from Amazon, ebay, etc for a 
couple bucks.

[toc] | [prev] | [next] | [standalone]


#3506

FromJohn Brooks <jbrooks@blueshiftinc.com>
Date2017-05-27 20:22 -0700
Message-ID<72f6633d-36d7-452e-a749-ee1751865f4a@googlegroups.com>
In reply to#3501
On Saturday, May 27, 2017 at 3:59:38 PM UTC-7, Luigi Thirty wrote:
> I'm doing some fixed-point math in my GS program and I'd like to be able to dump variables to the screen. I'm using the Integer Math Tool Set to do my calculations.
> 
> For example, I want to print the result of 100 * cos(45) and 16 bits of accuracy is enough. I can calculate it with the Integer tools...
> 
> ~FracCos R_45_degrees
> PullLong fixed_operand_1                   ; fixed_operand_1 = FRAC, .7854 radians
> ~Frac2Fix fixed_operand_1                  ; convert that to FIXED
> PullLong fixed_operand_1                   ; and pull it into the operand
> ~FixMul fixed_operand_1;fixed_operand_2    ; fixed_operand_2 = 100.0
> PullLong fixed_result                      ; 70.7106 or so
> 
> ...and then print the decimal part.
> 
> ~Int2Dec fixed_result+2;#str_output;#16;#1 ; signed value, 16-character string
> DrawString #str_output;#0;#0               ; my function
> 
> But the fractional value held in the word at fixed_result isn't decimal, it represents 1/65536, so I can't directly print it. I don't see a conversion in the Integer Tool Set that would allow me to print it, either. Is there a built-in call for approximating the fraction word of FIXED numbers in decimal form?

Multiply the low 16 bits of fixed_result by 10,000, then print the upper 16 bits of that result as 4 decimal digits.

Example with fixed_result = 70.7106
low 16 = $B5E9 (.7106 * 65536)
10000 * $B5E9 = $1BC1 DD90
$1BC1 = 7105

-JB
@JBrooksBSI

[toc] | [prev] | [next] | [standalone]


#3509

FromMichael Pohoreski <michael.pohoreski@gmail.com>
Date2017-05-28 08:39 -0700
Message-ID<513966e1-eaa5-4b7c-8402-a1b174e10e80@googlegroups.com>
In reply to#3506
I prefer to print fractional values by "digit peeling".

For n digits:
   24-bit multiply by $A (number in 8.16 format)
   convert integer portion to ASCII
   zero integer portion

It is trivial to optimize the x*10 as x*8 + x*2


Binary Demo
0800:a2 b5 a0 e9 20 15 08 a2 00 bd 70 08 20 ed fd e8
0810:e0 05 d0 f5 60 a9 00 8d 6a 08 8e 6b 08 8c 6c 08
0820:a2 00 20 60 08 20 54 08 20 60 08 20 60 08 20 44
0830:08 ad 6a 08 09 b0 9d 70 08 a9 00 8d 6a 08 e8 e0
0840:05 d0 df 60 18 a0 02 b9 6a 08 79 6d 08 99 6a 08
0850:88 10 f4 60 a0 02 b9 6a 08 99 6d 08 88 10 f7 60
0860:0e 6c 08 2e 6b 08 2e 6a 08 60 00 00 00 00 00 00
0870:00 00 00 00 00                                 
800G

Source -- assemble with merlin32

        ORG $800

; ==================== Demo ====================

Demo
        ; .7106 * 65536 = $B5E9
        ; A*B5E9
        ;=======
        ; 7.1B1A
        ; 1.0F04
        ; 0.9628
        ; 5.5DD90
        ; 8.A7A0
        LDX #$B5
        LDY #$E9
        JSR PrintFract

        LDX #0
PrintDigit
        LDA D0,X
        JSR $FDED
        INX
        CPX #5
        BNE PrintDigit
        RTS

; ==================== Conversion ====================

; --------------------
; Convert 16-bit fractional value to Decimal
; IN
;   X = high 16-bit val
;   Y = low  16-bit val
; OUT
;   [D0..D4] Decimal Fraction
; --------------------
PrintFract
        LDA #0
        STA A1
        STX A2
        STY A3

        LDX #0
NextDigit
        JSR Mul2    ; *2
        JSR CopyT2  ; x*10 = x*8 + x*2
        JSR Mul2    ; *4
        JSR Mul2    ; *8
        JSR AddT2

        LDA A1      ; Convert binary num to ASCII
        ORA #$30+$80
        STA D0,X

        LDA #0
        STA A1

        INX
        CPX #5
        BNE NextDigit
        RTS


; ==================== Utility ====================

; --------------------
; Add Arrays
; A += T
; --------------------
AddT2
        CLC
        LDY #2
_AddT2
        LDA A2-1,Y
        ADC T2-1,Y
        STA A2-1,Y
        DEY
        BPL _AddT2
        RTS

; --------------------
; Copy Array
;    T = A
; --------------------
CopyT2
        LDY #2
_CopyT2
        LDA A2-1,Y
        STA T2-1,Y
        DEY
        BPL _CopyT2
        RTS


; --------------------
; 24-bit SHL
; --------------------
Mul2
        ASL A3
        ROL A2
        ROl A1
        RTS

; ==================== Data ====================

; 24-bit Number
A1      DB 0
A2      DB 0
A3      DB 0

; Temp
T1      DB 0 ; Always zero
T2      DB 0
T3      DB 0

; String Output in ASCII
D0      DB 0
D1      DB 0
D2      DB 0
D3      DB 0
D4      DB 0

[toc] | [prev] | [next] | [standalone]


#3511

FromMichael Pohoreski <michael.pohoreski@gmail.com>
Date2017-05-28 10:47 -0700
Message-ID<a72dadb9-d00c-406d-bb20-7db4e9ab604d@googlegroups.com>
In reply to#3509
Note: Remove this incorrect comment

T1      DB 0 ; Always zero

[toc] | [prev] | [next] | [standalone]


#3510

Fromroger.shimada@gmail.com
Date2017-05-28 09:10 -0700
Message-ID<9ba6d87e-671e-4201-bdcf-37c506b7d0ad@googlegroups.com>
In reply to#3501
On Saturday, May 27, 2017 at 5:59:38 PM UTC-5, Luigi Thirty wrote:
> But the fractional value held in the word at fixed_result isn't decimal, it represents 1/65536, so I can't directly print it.

The pseudo code to print a fixed point fraction in decimal:

temp = fraction_of(absolute_value(value))
print decimal_character
while temp not = 0
  temp  = temp * 10
  digit = integer_of(temp)
  temp  = temp - digit  // or temp = fraction_of(temp)
  print digit

This is easier than converting integers to decimal.

[toc] | [prev] | [next] | [standalone]


#3513

FromLuigi Thirty <luigi30@gmail.com>
Date2017-05-29 14:12 -0700
Message-ID<9a30a637-b680-4106-ab29-e08126be821d@googlegroups.com>
In reply to#3501
Thanks, I got it and got my little program working. It rotates a square on the Super Hi-Res screen and doesn't do much else yet!

[toc] | [prev] | [next] | [standalone]


#3537

FromMichael Pohoreski <michael.pohoreski@gmail.com>
Date2017-06-11 07:46 -0700
Message-ID<5e4e0c08-89ab-4fee-99f7-128d7c17b23f@googlegroups.com>
In reply to#3513
I've added a git repo with (assembly) source and binary:
https://github.com/Michaelangel007/apple2_print_fixed16_fraction

Along with adding a proper introduction and cleaning up the conversion for readability to make it easy to follow along.
i.e.

    0.7106 * 65536 = $B5E9
                                  '.'
                     $B5E9 * $A = $7.1B1A
                     $1B1A * $A = $1.0F04
                     $0F04 * $A = $0.9628
                     $9628 * $A = $5.DD90
                     $5DD9 * $A = $8.A7A0

    0.71058 _______________________^

[toc] | [prev] | [next] | [standalone]


#3538

FromMichael J. Mahon <mjmahon@aol.com>
Date2017-06-11 10:33 -0500
Message-ID<irWdnRpr9PN7_6DEnZ2dnUU7-fHNnZ2d@giganews.com>
In reply to#3537
Michael Pohoreski <michael.pohoreski@gmail.com> wrote:
> I've added a git repo with (assembly) source and binary:
> https://github.com/Michaelangel007/apple2_print_fixed16_fraction
> 
> Along with adding a proper introduction and cleaning up the conversion
> for readability to make it easy to follow along.
> i.e.
> 
>     0.7106 * 65536 = $B5E9
>                                   '.'
>                      $B5E9 * $A = $7.1B1A
>                      $1B1A * $A = $1.0F04
>                      $0F04 * $A = $0.9628
>                      $9628 * $A = $5.DD90
>                      $5DD9 * $A = $8.A7A0
> 
>     0.71058 _______________________^
> 

Just for completeness, note that it's only necessary to do as many
multiplies by ten as you need digits, since the high bit of the last
fractional part tells you whether the last digit needs to be rounded up. 

-- 
-michael - NadaNet 3.1 and AppleCrate II:  http://michaeljmahon.com

[toc] | [prev] | [next] | [standalone]


#3614

FromMichael Pohoreski <michael.pohoreski@gmail.com>
Date2017-06-30 09:32 -0700
Message-ID<91da5ae7-f320-4153-b925-32c081849f7b@googlegroups.com>
In reply to#3538
On Sunday, June 11, 2017 at 8:34:03 AM UTC-7, mjm...@aol.com wrote:

> since the high bit of the last
> fractional part tells you whether the last digit needs to be rounded up. 

That's a great tip!

It interesting what you forget when you haven't used this stuff for 20 years. :-) 

[toc] | [prev] | [standalone]


Back to top | Article view | comp.sys.apple2.programmer


csiph-web