Author Topic: How to define data types for a function  (Read 2867 times)

0 Members and 1 Guest are viewing this topic.

Offline SI

  • Newbie
  • Posts: 2
    • View Profile
How to define data types for a function
« on: April 03, 2019, 03:03:39 pm »
Hello!

Could you fix the errors?

DIM x1 AS _INTEGER64: DIM y1 AS _INTEGER64: DIM z1 AS _INTEGER64: DIM t1 AS _INTEGER64
DIM x2 AS _INTEGER64: DIM y2 AS _INTEGER64: DIM z2 AS _INTEGER64: DIM t2 AS _INTEGER64
DIM x3 AS _INTEGER64: DIM y3 AS _INTEGER64: DIM z3 AS _INTEGER64: DIM t3 AS _INTEGER64
DIM x AS _INTEGER64: DIM y AS _INTEGER64: DIM z AS _INTEGER64: DIM t AS _INTEGER64

RESTORE
READ x1: READ y1: READ z1: READ t1
READ x2: READ y2: READ z2: READ t2
READ x3: READ y3: READ z3: READ t3

x = r(t1, y1, z1, t2, y2, z2, t3, y3, z3)
PRINT x

END
????? DIM r AS
FUNCTION r (a1, b1, c1, a2, b2, c2, a3, b3, c3)
?????
    DIM a1 AS _INTEGER64: DIM b1 AS _INTEGER64: DIM c1 AS _INTEGER64
    DIM a2 AS _INTEGER64: DIM b2 AS _INTEGER64: DIM c2 AS _INTEGER64
    DIM a3 AS _INTEGER64: DIM b3 AS _INTEGER64: DIM c3 AS _INTEGER64

    r = a1 * b2 * c3 + a2 * b3 * c1 + a3 * b1 * c2
    r = r - a3 * b2 * c1 - a1 * b3 * c2 - a2 * b1 * c3
END FUNCTION

DATA 3,4,5,6
DATA 1,6,8,9
DATA 3,10,18,19

Marked as best answer by SI on April 03, 2019, 11:46:25 am

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: How to define data types for a function
« Reply #1 on: April 03, 2019, 03:34:28 pm »
Hi SI
welcome to QB64 forum

1) why do you not  post the code in the dedicated box ?  (when you write a message use the # button to create a box for code!)
it is easier for other member to copy and paste your code.

2)what is the exact result of the function r that you think to get back?
(8 is ok for your example?)

3) _INTEGER64 is a wide type of integer (-9223372036854775808 to 9223372036854775807) while SINGLE (-2.802597E-45    to +3.402823E+38) is a different kind of number (see here for details http://qb64.org/wiki/Variable_Types)
you declare a Function as single (see here for synthax of FUNCTION http://qb64.org/wiki/FUNCTION)
and you pass all parameters as _INTEGER64 ... IMHO the result of calculation will be adapted to the type of Function before to be put back, so you must declare FUNCTION r&& at the place of FUNCTION r.

4) I know that the name of a function can be used to put back the result of the function and not as variable , moreover if you use the function both at left both at right of an equation you are doing a recursive calling to that function but you need to pass parameters needed
here the code working if the goal is to do those calculations:
Code: QB64: [Select]
  1.  
  2. READ x1: READ y1: READ z1: READ t1
  3. READ x2: READ y2: READ z2: READ t2
  4. READ x3: READ y3: READ z3: READ t3
  5.  
  6. x = r&&(t1, y1, z1, t2, y2, z2, t3, y3, z3)
  7.  
  8.  
  9.     '?????
  10.     '    DIM a1 AS _INTEGER64: DIM b1 AS _INTEGER64: DIM c1 AS _INTEGER64
  11.     '   DIM a2 AS _INTEGER64: DIM b2 AS _INTEGER64: DIM c2 AS _INTEGER64
  12.     '  DIM a3 AS _INTEGER64: DIM b3 AS _INTEGER64: DIM c3 AS _INTEGER64
  13.     DIM r1
  14.     r1 = a1 * b2 * c3 + a2 * b3 * c1 + a3 * b1 * c2
  15.     r = r1 - a3 * b2 * c1 - a1 * b3 * c2 - a2 * b1 * c3
  16.  
  17. DATA 3,4,5,6
  18. DATA 1,6,8,9
  19. DATA 3,10,18,19
  20.  
  21.  
Programming isn't difficult, only it's  consuming time and coffee

Offline SI

  • Newbie
  • Posts: 2
    • View Profile
Re: How to define data types for a function
« Reply #2 on: April 03, 2019, 03:44:59 pm »
Thanks for the reply.