Active Forums => QB64 Discussion => Topic started by: SI on April 03, 2019, 03:03:39 pm
Title: How to define data types for a function
Post by: SI 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
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
Title: Re: How to define data types for a function
Post by: TempodiBasic 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 (http://qb64.org/wiki/Variable_Types)) you declare a Function as single (see here for synthax of FUNCTION http://qb64.org/wiki/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: