Author Topic: If I float with ccz80 ++ use then are set in the screen pixel.  (Read 1967 times)

0 Members and 1 Guest are viewing this topic.

Offline cpcuser

  • CPC664
  • ***
  • Posts: 73
  • Country: de
  • Liked: 15
  • Likes Given: 0
Hi good afternoon.

If I float with ccz80 ++ use then are set in the screen pixel.
I print with print the value not yet.

What is the reason?
Must any ram / rom be switched on and off before the floatroutine?

Thank you.
greeting

Code: [Select]

include Indirections6128.ccz80++
include Float.ccz80++


class Test
{
  static void main()
  {
     int wert1;
      int wert2;
     
      int wert3;
      int wert4;
     
      int wert5;
      int wert6;
     
      wert1="3234.623";
      wert3="4321.713";
     
      Float.DecToFloat(wert2, wert1);   
      Float.DecToFloat(wert4, wert3);
      wert5=Float.Add(wert2,wert4);   
     
      wert6=Float.FloatToInt(wert5);
  }
}

Offline andycadley

  • Supporter
  • 6128 Plus
  • *
  • Posts: 928
  • Liked: 458
  • Likes Given: 73
Your variables are all of type int, but the values you are assigning to them aren't int values. They'll overflow and corrupt memory, leading to unpredictable results, which may well include corruption of the screen.

Offline cpcuser

  • CPC664
  • ***
  • Posts: 73
  • Country: de
  • Liked: 15
  • Likes Given: 0

How do you have to look the variable?


Thank you.
greeting

Offline cpcuser

  • CPC664
  • ***
  • Posts: 73
  • Country: de
  • Liked: 15
  • Likes Given: 0
The result is ok.

Where is the error please?

Thank you.

Code: [Select]

include Indirections6128.ccz80++
include Text.ccz80++
include Float.ccz80++


class Test
{
  static void main()
  {
     int wert1;
      int wert2;
     
      int wert3;
      int wert4;
     
      int wert5;
      int wert6;
     
      wert1="3234.623";
      wert3="4321.713";
     
      Float.DecToFloat(wert2, wert1);   
      Float.DecToFloat(wert4, wert3);
     
      wert5=Float.Add(wert2,wert4);   
     
      wert6=Float.FloatToInt(wert5);
      Text.PrintString("\n\r");   
      Text.PrintInt(wert6);   
  }
}

Offline AMSDOS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 3.939
  • Country: au
    • index.php?action=treasury
    • Programs for Turbo Pascal 3
  • Liked: 1157
  • Likes Given: 1924
Shouldn't all those int declarations be float, if that's the case you shouldn't need "flat.dectofloat"

Code: [Select]
  static void main()
  {
     float wert1;
      float wert2;
     
      float wert3;
      float wert4;
     
      float wert5;
      float wert6;
..

* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

Offline cpcuser

  • CPC664
  • ***
  • Posts: 73
  • Country: de
  • Liked: 15
  • Likes Given: 0

Variable float does not exist in ccz80 ++


greeting

Offline SRS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 628
  • Country: de
  • Schneider CPC464 - what else ?
  • Liked: 627
  • Likes Given: 363
If FLOAT does not exist, why there are "Float"-Routines? Seems not logic to me.


Offline cpcuser

  • CPC664
  • ***
  • Posts: 73
  • Country: de
  • Liked: 15
  • Likes Given: 0

this is the floatroutine from ccz80++ :

Code: [Select]

include Text.ccz80++
include Printer.ccz80++
include File.ccz80++


class Float
{
  public static int Copy(int argument1, int argument2)
    asm (Indirections.Values())
    {
      ld   hl,2
      add  hl,sp
      ld   e,(hl)
      inc  hl
      ld   d,(hl)                             ; DE = 2nd parameter
      inc  hl
      ld   a,(hl)
      inc  hl
      ld   h,(hl)
      ld   l,a                                ; HL = 1st parameter
      jp   __move_real
    }


  public static int ShortToFloat(int argument1, short argument2)
    asm (Indirections.Values())
    {
      ld   hl,3
      add  hl,sp
      ld   a,(hl)                             ; A = 2nd parameter
      inc  hl
      ld   e,(hl)
      inc  hl
      ld   d,(hl)                             ; DE = 1st parameter
      ld   h,0
      ld   l,a                                ; HL = 2nd parameter copy
      xor  a
      jp   __integer_to_real
    }


  public static int IntToFloat(int argument1, int argument2)
    asm (Indirections.Values())
    {
      ld   hl,2
      add  hl,sp
      ld   e,(hl)
      inc  hl
      ld   d,(hl)                             ; DE = 2nd parameter
      inc  hl
      ld   a,(hl)
      inc  hl
      ld   h,(hl)
      ld   l,a                                ; HL = 1st parameter
      ex   de,hl                              ; DE = real address, HL = value
      xor  a
      jp   __integer_to_real
    }


  public static short FloatToShort(int argument1)
    asm register (Indirections.Values())
    {
      call __real_to_integer
      ld   a,l
      ret  p                                  ; Value is positive
      neg
      ret
    }


  public static int FloatToInt(int argument1)
    asm register (Indirections.Values())
    {
      call __real_to_integer
      ret  p                                  ; Value is positive
      ld   de,0
      ex   de,hl
      or   a
      sbc  hl,de
      ret
    }


  public static int LongToFloat(int argument1, int argument2)
    asm (Indirections.Values())
    {
      ld   hl,2
      add  hl,sp
      ld   e,(hl)
      inc  hl
      ld   d,(hl)                             ; DE = 2nd parameter
      inc  hl
      ld   a,(hl)
      inc  hl
      ld   h,(hl)
      ld   l,a                                ; HL = 1st parameter
      ex   de,hl                              ; DE = real address, HL = long address
      push de                                 ; Save real address
      ld   bc,4
      ldir
      pop  hl                                 ; Restore real address
      xor  a
      jp   __binary_to_real
    }


  public static int FloatToLong(int argument1, int argument2)
    asm (Indirections.Values())
    {
      ld   hl,2
      add  hl,sp
      ld   e,(hl)
      inc  hl
      ld   d,(hl)                             ; DE = 2nd parameter
      inc  hl
      ld   a,(hl)
      inc  hl
      ld   h,(hl)
      ld   l,a                                ; HL = 1st parameter
      ex   de,hl                              ; DE = real address, HL = long address
      push de                                 ; Save real address
      ld   bc,4
      ldir
      pop  hl                                 ; Restore real address
      xor  a
      call __real_to_binary
      ld   a,b
      rlca
      ret  nc                                 ; Value is positive
      ex   de,hl                              ; Save result address in DE
      ld   b,4
      or   a
      __ftol_1:
      ld   a,0
      sbc  a,(hl)
      ld   (hl),a
      inc  hl
      djnz __ftol_1
      ex   de,hl                              ; HL = Restore result address in HL
      ret
    }


  public static int FloatToDec(int argument1, int argument2)
    asm (Indirections.Values())
    {
      ld   hl,2
      add  hl,sp
      ld   e,(hl)
      inc  hl
      ld   d,(hl)                             ; DE = 2nd parameter
      inc  hl
      ld   a,(hl)
      inc  hl
      ld   h,(hl)
      ld   l,a                                ; HL = 1st parameter
      __ftoa_0:                               ; Entry for another functions
      push hl
      push hl                                 ; Save string address (twice)
      ld   hl,__ftoa_8
      ld   (__ftoa_7),hl                      ; Initialize weight address
      ld   hl,__ftoa_9
      call __move_real                        ; Copy real value
      ld   a,3
      call __real_10a                         ; Pass 3 decimal digits to integer part
      call __real_to_binary
      pop  hl                                 ; Restore string address
      bit  7,b
      jr   z,__ftoa_1
      ld   (hl),"-"
      inc  hl
      __ftoa_1:
      ld   b,9
      __ftoa_2:
      push bc                                 ; Save digit counter
      ld   a,b
      cp   2
      jr   nz,__ftoa_3
      ld   (hl),"."
      inc  hl
      __ftoa_3:
      push hl                                 ; Save string pointer
      ld   c,"0"-1
      __ftoa_4:
      inc  c
      ld   de,__ftoa_9
      ld   hl,(__ftoa_7)
      or   a
      ld   b,4
      __ftoa_5:
      ld   a,(de)
      sbc  a,(hl)
      ld   (de),a
      inc  de
      inc  hl
      djnz __ftoa_5
      jr   nc,__ftoa_4
      ld   de,__ftoa_9
      ld   hl,(__ftoa_7)
      or   a
      ld   b,4
      __ftoa_6:
      ld   a,(de)
      adc  a,(hl)
      ld   (de),a
      inc  de
      inc  hl
      djnz __ftoa_6
      pop  hl                                 ; Restore string pointer
      ld   (hl),c
      inc  hl
      ld   de,(__ftoa_7)
      inc  de
      inc  de
      inc  de
      inc  de
      ld   (__ftoa_7),de                      ; Setup weight address
      pop  bc                                 ; Restore digit counter
      djnz __ftoa_2
      ld   a,(__ftoa_9)
      add  a,"0"
      ld   (hl),a                             ; Store units
      inc  hl
      ld   (hl),0
      pop  hl                                 ; Restore string address
      ret
      __ftoa_7: defw 0
      __ftoa_8: defb #00, #CA, #9A, #3B       ; Weight 1000000000
      defb #00, #E1, #F5, #05       ; Weight 100000000
      defb #80, #96, #98, #00       ; Weight 10000000
      defb #40, #42, #0F, #00       ; Weight 1000000
      defb #A0, #86, #01, #00       ; Weight 100000
      defb #10, #27, #00, #00       ; Weight 10000
      defb #E8, #03, #00, #00       ; Weight 1000
      defb #64, #00, #00, #00       ; Weight 100
      defb #0A, #00, #00, #00       ; Weight 10
      __ftoa_9: defs 5                        ; Value
    }


  public static int DecToFloat(int argument1, int argument2)
    asm (Indirections.Values())
    {
      ld   de,__atof_8
      ld   hl,__atof_11
      call __move_real                        ; Copy real value 1 to weight
      xor  a
      ld   (__atof_10),a                      ; Initialize decimal point Counter
      ld   hl,2
      add  hl,sp
      ld   e,(hl)
      inc  hl
      ld   d,(hl)                             ; DE = 2nd paraemter
      inc  hl
      ld   a,(hl)
      inc  hl
      ld   h,(hl)
      ld   l,a                                ; HL = 1st parameter
      ld   a,(de)
      cp   "-"
      jr   nz,__atof_1                        ; Not specified minus sign
      push hl                                 ; Save real address
      ld   hl,__atof_11
      call __real_unary_minus
      inc  de
      pop  hl                                 ; Restore real address
      __atof_1:
      push de                                 ; Save string address
      push hl
      push hl                                 ; Save real address (twice)
      ld   b,-2
      __atof_2:
      inc  b
      ld   a,(de)
      cp   "0"
      jr   c,__atof_3
      cp   "9"+1
      jr   nc,__atof_3
      inc  de
      jr   __atof_2
      __atof_3:
      ld   a,b                                ; A = digits number in integer part minus one
      ld   hl,__atof_11
      call __real_10a
      pop  hl                                 ; Restore real address
      xor  a
      ld   b,5
      __atof_4:
      ld   (hl),a
      inc  hl
      djnz __atof_4                           ; Real value = 0
      pop  hl                                 ; Restore real address
      pop  de                                 ; Restore string address
      __atof_5:
      ld   a,(de)
      cp   "."
      jr   nz,__atof_6
      ld   a,(__atof_10)
      or   a
      ret  nz                                 ; Found a second decimal point
      inc  a
      ld   (__atof_10),a
      jr   __atof_7
      __atof_6:
      cp   "0"
      ret  c                                  ; Found a non digit
      cp   "9"+1
      ret  nc                                 ; Found a non digit
      push de                                 ; Save string pointer
      push hl
      push hl                                 ; Save real address
      sub  "0"
      ld   de,__atof_12
      ld   h,0
      ld   l,a
      xor  a
      call __integer_to_real
      ld   de,__atof_11
      call __real_multiplication
      pop  de                                 ; Restore real address
      ex   de,hl                              ; DE = digit value, HL = real address
      call __real_addition
      ld   hl,__atof_11
      ld   de,__atof_9
      call __real_division
      pop  hl                                 ; Restore real address
      pop  de                                 ; Restore string pointer
      __atof_7:
      inc  de
      jr   __atof_5
      __atof_8: defb #00, #00, #00, #00, #81  ; Real value 1
      __atof_9: defb #00, #00, #00, #20, #84  ; Real value 10
      __atof_10: defb 0                       ; Decimal point Counter
      __atof_11: defs 5                       ; Weight
      __atof_12: defs 5                       ; Digit value
    }


  public static int Add(int argument1, int argument2)
    asm (Indirections.Values())
    {
      ld   hl,2
      add  hl,sp
      ld   e,(hl)
      inc  hl
      ld   d,(hl)                             ; DE = 2nd paraemter
      inc  hl
      ld   a,(hl)
      inc  hl
      ld   h,(hl)
      ld   l,a                                ; HL = 1st parameter
      jp   __real_addition
    }


  public static int Sub(int argument1, int argument2)
    asm (Indirections.Values())
    {
      ld   hl,2
      add  hl,sp
      ld   e,(hl)
      inc  hl
      ld   d,(hl)                             ; DE = 2nd paraemter
      inc  hl
      ld   a,(hl)
      inc  hl
      ld   h,(hl)
      ld   l,a                                ; HL = 1st parameter
      call __real_reverse_subtraction
      jp   __real_unary_minus
    }


  public static int Mul(int argument1, int argument2)
    asm (Indirections.Values())
    {
      ld   hl,2
      add  hl,sp
      ld   e,(hl)
      inc  hl
      ld   d,(hl)                             ; DE = 2nd paraemter
      inc  hl
      ld   a,(hl)
      inc  hl
      ld   h,(hl)
      ld   l,a                                ; HL = 1st parameter
      jp   __real_multiplication
    }


  public static int Div(int argument1, int argument2)
    asm (Indirections.Values())
    {
      ld   hl,2
      add  hl,sp
      ld   e,(hl)
      inc  hl
      ld   d,(hl)                             ; DE = 2nd paraemter
      inc  hl
      ld   a,(hl)
      inc  hl
      ld   h,(hl)
      ld   l,a                                ; HL = 1st parameter
      jp   __real_division
    }


  public static short Cmp(int argument1, int argument2)
    asm (Indirections.Values())
    {
      ld   hl,2
      add  hl,sp
      ld   e,(hl)
      inc  hl
      ld   d,(hl)                             ; DE = 2nd paraemter
      inc  hl
      ld   a,(hl)
      inc  hl
      ld   h,(hl)
      ld   l,a                                ; HL = 1st parameter
      jp   __real_comparison
    }


  public static int Abs(int argument1)
    asm inline (Indirections.Values())
    {
      call __real_signum_sgn
      call c,__real_unary_minus
    }


  public static int Atn(int argument1)
    asm inline (Indirections.Values())
    {
      call __real_arctangent
    }


  public static int Cos(int argument1)
    asm inline (Indirections.Values())
    {
      call __real_cosine
    }


  public static int Exp(int argument1)
    asm inline (Indirections.Values())
    {
      call __real_exp
    }


  public static int Fix(int argument1)
    asm inline (Indirections.Values())
    {
      call __real_fix
      xor  a
      call __binary_to_real
    }


  public static int Cint(int argument1)
    asm inline (Indirections.Values())
    {
      call __real_int
      xor  a
      call __binary_to_real
    }


  public static int Log(int argument1)
    asm inline (Indirections.Values())
    {
      call __real_log
    }


  public static int Log10(int argument1)
    asm inline (Indirections.Values())
    {
      call __real_log_10
    }


  public static int Neg(int argument1)
    asm inline (Indirections.Values())
    {
      call __real_unary_minus
    }


  public static int Pi(int argument1)
    asm inline (Indirections.Values())
    {
      call __real_pi
    }


  public static int Pow(int argument1, int argument2)
    asm (Indirections.Values())
    {
      ld   hl,2
      add  hl,sp
      ld   e,(hl)
      inc  hl
      ld   d,(hl)                             ; DE = 2nd parameter
      inc  hl
      ld   a,(hl)
      inc  hl
      ld   h,(hl)
      ld   l,a                                ; HL = 1st parameter
      jp   __real_power
    }


  public static int Round(int argument1, short argument2)
    asm (Indirections.Values())
    {
      ld   hl,3
      add  hl,sp
      ld   a,(hl)                             ; A = 2nd parameter
      inc  hl
      ld   e,(hl)
      inc  hl
      ld   d,(hl)                             ; DE = 1st parameter
      push de                                 ; Save real address
      push af
      push af                                 ; Save precision (twice)
      ld   de,__round_1
      ld   hl,__round_2
      call __move_real                        ; Copy real value 1 to work space
      pop  af                                 ; Restore precision
      call __real_10a
      pop  af                                 ; Restore precision
      pop  hl                                 ; Restore real address
      call __real_10a
      call __real_to_binary
      ld   a,b
      call __binary_to_real
      ld   de,__round_2
      jp   __real_division
      __round_1: defb #00, #00, #00, #00, #81 ; Real value 1
      __round_2: defs 5                       ; Work space
    }


  public static short Sgn(int argument1)
    asm inline (Indirections.Values())
    {
      call __real_signum_sgn
    }


  public static int Sin(int argument1)
    asm inline (Indirections.Values())
    {
      call __real_sine
    }


  public static int Sqr(int argument1)
    asm inline (Indirections.Values())
    {
      call __real_sqr
    }


  public static int Tan(int argument1)
    asm inline (Indirections.Values())
    {
      call __real_tangent
    }


  public static void Deg()
    asm inline (Indirections.Values())
    {
      ld   a,#FF
      call __set_angle_mode
    }


  public static void Rad()
    asm inline (Indirections.Values())
    {
      xor  a
      call __set_angle_mode
    }


  public static void Print(int argument1)
    asm register (FloatToDec(0, 0), Text.PrintString(0))
    {
      ld   de,__printf_1
      ex   de,hl                              ; DE = value, HL = string address
      call __ftoa_0
      jp   __prints_0
      __printf_1: defs 13
  }


  public static void PrinterPrint(int argument1)
    asm register (FloatToDec(0, 0), Printer.PrintString(0))
    {
      ld   de,__lprintf_1
      ex   de,hl                              ; DE = value, HL = string address
      call __ftoa_0
      jp   __lprints_0
      __lprintf_1: defs 13
  }


  public static void FilePrint(int argument1)
    asm register (FloatToDec(0, 0), File.PrintString(0))
    {
      ld   de,__fprintf_1
      ex   de,hl                              ; DE = value, HL = string address
      call __ftoa_0
      jp   __fprints_0
      __fprintf_1: defs 13
  }
}

Offline SRS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 628
  • Country: de
  • Schneider CPC464 - what else ?
  • Liked: 627
  • Likes Given: 363
Okay, it's using the firmware.





First : there is a specific forum for CCZ80 -> you should ask them, as they know their tool:

http://ccz80pp.foroactivo.com/login

Second:

As you can see, the firmware does not need a int variable (which cant hold  "3234.623")

It needs a pointer to a place in memory with a real (float) variable, which is a  five byte array

so lets say:

Code: [Select]
// Reserve space
short wert1[5];
short wert2[5];
short wert3[5];
int wert4;

wert4=3234;

Float.IntToFloat(wert4, &wert1);

wert4=123;

Float.IntToFloat(wert4, &wert2);

Float.Mul(&wert1, &wert2); // 123*3234

Float.Pi(&wert3);

Float.Div(&wert1, & wert3); // 123*3234/PI

Float.Print(&wert1);

....

Should work better.

IF I understood the source code of the library, of course :)

Again: better ask at the forum for that tool.


Offline Arnaud

  • Supporter
  • 6128 Plus
  • *
  • Posts: 683
  • Country: fr
  • Liked: 601
  • Likes Given: 1227
Float.IntToFloat(wert4, &wert1);

@SRS I'm not sure the & is needed, an array can be considered as a pointer, in this case &wert is a pointer of pointer of short. And i think the int wert4 argument shall be passed as pointer.

@cpcuser If your code doesn't works try this

Code: [Select]
// Reserve space
short wert1[5];
short wert2[5];
short wert3[5];
int wert4;

wert4=3234;

Float.IntToFloat(&wert4, wert1);

wert4=123;

Float.IntToFloat(&wert4, wert2);

Float.Mul(wert1, wert2); // 123*3234

Float.Pi(wert3);

Float.Div(wert1, wert3); // 123*3234/PI

Float.Print(wert1);

....
« Last Edit: 22:23, 25 February 17 by Arnaud »

Offline cpcuser

  • CPC664
  • ***
  • Posts: 73
  • Country: de
  • Liked: 15
  • Likes Given: 0
Re: If I float with ccz80 ++ use then are set in the screen pixel.
« Reply #10 on: 10:01, 26 February 17 »
Hi good afternoon.
Result is still not true.

Hello arnaud, your suggestion brings error

Thank you.
greeting

Code: [Select]

include Indirections6128.ccz80++
include Text.ccz80++
include Float.ccz80++


class Test
{
  static void main()
  {
short wert1[5];
short wert2[5];
short wert3[5];
int wert4;


wert4=3234;


Float.IntToFloat(wert4, &wert1);


wert4=123;


Float.IntToFloat(wert4, &wert2);


Float.Mul(&wert1, &wert2); // 123*3234


Float.Pi(&wert3);


Float.Div(&wert1, & wert3); // 123*3234/PI


Float.Print(&wert1);


  }
}
« Last Edit: 10:03, 26 February 17 by cpcuser »

Offline arnoldemu

  • Supporter
  • 6128 Plus
  • *
  • Posts: 5.336
  • Country: gb
    • Unofficial Amstrad WWW Resource
  • Liked: 2278
  • Likes Given: 3478
Re: If I float with ccz80 ++ use then are set in the screen pixel.
« Reply #11 on: 12:04, 26 February 17 »
Tip: Output each value to check all is correct to find problem. This I always do.

If making code for PC, I would use debugger in Visual Studio 2015 because you can look at variables directly and follow each line of code. We don't have this for ccz80++ and CPC, so output each result to screen.

I output all values and find something wrong with inttofloat:
Code: [Select]
include Indirections6128.ccz80++
include Text.ccz80++
include Float.ccz80++


class Test
{
  static void main()
  {
short wert1[5];
short wert2[5];
short wert3[5];
int wert4;


wert4=3234;

Float.IntToFloat(wert4, &wert1);
Float.Print(&wert1);
Text.PrintString("\r\n");

wert4=123;


Float.IntToFloat(wert4, &wert2);
Float.Print(&wert2);
Text.PrintString("\r\n");

Float.Mul(&wert1, &wert2); // 123*3234
Float.Print(&wert1);
Text.PrintString("\r\n");

Float.Pi(&wert3);
Float.Print(&wert3);
Text.PrintString("\r\n");

Float.Div(&wert1, &wert3); // 123*3234/PI


Float.Print(&wert1);
Text.PrintString("\r\n");


  }
}

Then I looked at the library code and found the answer:

IntToFloat(float,int)

you wrote

IntToFloat(int, float)

Fixed:

Code: [Select]
include Indirections6128.ccz80++
include Text.ccz80++
include Float.ccz80++


class Test
{
  static void main()
  {
short wert1[5];
short wert2[5];
short wert3[5];
int wert4;


wert4=3234;

Float.IntToFloat(&wert1,wert4);
Float.Print(&wert1);
Text.PrintString("\r\n");

wert4=123;


Float.IntToFloat(&wert2,wert4);
Float.Print(&wert2);
Text.PrintString("\r\n");

Float.Mul(&wert1, &wert2); // 123*3234
Float.Print(&wert1);
Text.PrintString("\r\n");

Float.Pi(&wert3);
Float.Print(&wert3);
Text.PrintString("\r\n");

Float.Div(&wert1, &wert3); // 123*3234/PI


Float.Print(&wert1);
Text.PrintString("\r\n");


  }
}

Answer is correct now.
My games. My Games
My website with coding examples: Unofficial Amstrad WWW Resource

Offline Arnaud

  • Supporter
  • 6128 Plus
  • *
  • Posts: 683
  • Country: fr
  • Liked: 601
  • Likes Given: 1227
Re: If I float with ccz80 ++ use then are set in the screen pixel.
« Reply #12 on: 12:12, 26 February 17 »
Here a working code.

I found the order of the parameters is not logical

IntToFloat : Int -> Float shall be
Code: [Select]
InToFloat(Int arg1, Float arg2)
and they are inverted:
Code: [Select]
InToFloat(Float arg1, Int arg2)
Edit:
It's certainly the ccz80++ convention : Function(Out arg, In arg)  ::)


Code: [Select]
include Indirections6128.ccz80++
include Text.ccz80++
include Float.ccz80++

class Test
{
  static void main()
  {
    int wert1[2];    // Float takes 4 bytes (int = 2 bytes)
    int wert2[2];    // Float takes 4 bytes (int = 2 bytes)
    int wert3[2];    // Float takes 4 bytes (int = 2 bytes)
    int wert4;

    wert4 = 3234;

    Float.IntToFloat(&wert1, wert4); // IntToFloat(Out, In)
    Float.Print(&wert1);
    Text.PrintString("\n\r");
   
    wert4 = 123;
    Float.IntToFloat(&wert2, wert4);
    Float.Print(&wert2);
    Text.PrintString("\n\r");
   
    Float.Mul(&wert1, &wert2);
    Float.Print(&wert1);
    Text.PrintString("\n\r");
   
    Float.Pi(&wert3);
    Float.Print(&wert3);
    Text.PrintString("\n\r");
   
    Float.Div(&wert1, &wert3); // 123*3234/PI
    Float.Print(&wert1);
    Text.PrintString("\n\r");
  }
}
« Last Edit: 12:19, 26 February 17 by Arnaud »

Offline cpcuser

  • CPC664
  • ***
  • Posts: 73
  • Country: de
  • Liked: 15
  • Likes Given: 0
Re: If I float with ccz80 ++ use then are set in the screen pixel.
« Reply #13 on: 13:33, 26 February 17 »

Hello arnoldemu and  arnaud, your program works!
I did not pay attention to the int and float exchanged.  >>>>>>>>>>> IntToFloat(Out, In) !!!


Thank you.
greeting
« Last Edit: 19:28, 26 February 17 by cpcuser »

Offline cpcuser

  • CPC664
  • ***
  • Posts: 73
  • Country: de
  • Liked: 15
  • Likes Given: 0
Re: If I float with ccz80 ++ use then are set in the screen pixel.
« Reply #14 on: 21:00, 26 February 17 »

Hi good afternoon.
Sinus and Cosinus works wonderfully with Float.

Thank you.
greeting


Real are floating-point numbers whose internal encoding requires 5 bytes.


Code: [Select]
include Indirections6128.ccz80++
include Text.ccz80++
include Float.ccz80++
include Graphics.ccz80++

class Test
{
   static int x,y,xp,yp;
   static int grad;
 
  static void main()
  {
      short fadr1[5];
      short fadr2[5];
      short fadr3[5];
      short fadr4[5];
      short fadr5[5];
      short fadr6[5];
     
      short pi180[5]; 
      short radius[5];   
     
     static short wert1[]="0.017";     
      static short wert2[]="150.0";     
     
      Float.DecToFloat(&fadr1,&wert1);
      Float.Copy(&pi180,&fadr1);   
     
      Float.DecToFloat(&fadr1,&wert2);
      Float.Copy(&radius,&fadr1);   
     
      Graphics.Clg();     
   
      for (grad = 0; grad <= 368; grad=grad+1)   
         {
            Float.IntToFloat(&fadr1, grad);
            Float.Copy(&fadr2,&fadr1);   
            Float.Copy(&fadr3,&pi180);
            Float.Mul(&fadr3,&fadr2);
            Float.Sin(&fadr3);
            Float.Mul(&fadr3,&radius);
            Float.Copy(&fadr4,&fadr3);
           
            Float.IntToFloat(&fadr1, grad);
            Float.Copy(&fadr2,&fadr1);   
            Float.Copy(&fadr3,&pi180);
            Float.Mul(&fadr3,&fadr2);
            Float.Cos(&fadr3);
            Float.Mul(&fadr3,&radius);
            Float.Copy(&fadr5,&fadr3);     
           
            x=Float.FloatToInt(&fadr4);         
            y=Float.FloatToInt(&fadr5);
           
            xp=x+320;
            yp=y+200;
           
            Graphics.Plot(xp,yp);           
         }   
  }
}
« Last Edit: 18:46, 27 February 17 by cpcuser »

Offline SRS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 628
  • Country: de
  • Schneider CPC464 - what else ?
  • Liked: 627
  • Likes Given: 363
Re: If I float with ccz80 ++ use then are set in the screen pixel.
« Reply #15 on: 21:41, 28 February 17 »
Quote
Real are floating-point numbers whose internal encoding requires 5 bytes.


As I said :p

Offline Arnaud

  • Supporter
  • 6128 Plus
  • *
  • Posts: 683
  • Country: fr
  • Liked: 601
  • Likes Given: 1227
Re: If I float with ccz80 ++ use then are set in the screen pixel.
« Reply #16 on: 22:15, 28 February 17 »


As I said :p


CPC Firmware float encoding ?

Offline SRS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 628
  • Country: de
  • Schneider CPC464 - what else ?
  • Liked: 627
  • Likes Given: 363
Re: If I float with ccz80 ++ use then are set in the screen pixel.
« Reply #17 on: 22:23, 28 February 17 »
yep. ccz80 uses the firmware float lib (the well known z80-40bit float i guess).

there must be some faster out there, with z88dk libs i.e.

Offline cpcuser

  • CPC664
  • ***
  • Posts: 73
  • Country: de
  • Liked: 15
  • Likes Given: 0

Z88dk is dead for the CPC.
Since the forum is nothing more.
Since no one is programming for the CPC.




greeting