PureBasic – pbF64

Usage

Here I will show you some simple steps to your first F64 Calculations.

·         Defining F64 Numbers

let df denote a Double Float

Defining a new double variable is as easy as

df.double

·         Assigning values
Values can be assigned to an double by simply calling one of the following functions.

F64_Val(df.double, "42.2342"); Assigns a numeric string to the double

float.f = 42.2342
F64_Float(df.double, float); Assigns a float to the double

int.l = 42
F64_Int(df.double, int); Assigns a long to the double

·         Calculation
All Functions expecting a double as result are writing this result in the first passed double parameter (df1 or df in the descriptions).

Example:

df1.double

df2.double

F64_Val(df1, "23") ;df1 becomes 23

F64_Val(df2, "19") ;df2   -"-   19

F64_Add(df1, df2)  ;df1 should now be 42 while df2 remains 19

Since version 0.9 the result can also be stored in an optional parameter. In this case, the first parameter stays untouched.

Example:

df1.double

df2.double

result.double

F64_Val(df1, "23") ;df1 becomes 23

F64_Val(df2, "19") ;df2 becomes 19

F64_Add(df1, df2, result)  ;df1 should now still be 23, df2 remains 19 too. result will be the only changed variable, it's value now 42.

·         Comparing values
Once you have calculated some values, you sure need to compare them to each other.
Here too you have two syntaxes.
This compares two numbers to each other and returns an integer value as result.

integer.l = F64_Cmp(df.double, df2.double)

This one also compares the two numbers, but stores the result in another double and returns the result in a long integer

comp.l = F64_Cmp(df.double, df2.double, result.double)

·         Output
In the end you surely will output the numbers in a suitable format. We have several functions for this
For example:

string.s = F64_Str(df.double, 5, #F64_Format_Scientific)

This will return the number as a numeric string in exponential/scientific notation (4.22342E+1).(

string.s = F64_Str(df.double, 4, #F64_Format_Decimal)

This will return a normal fixed point notational string (42.2342)

Or

String.s = F64_Str(df.double, 15, #F64_Format_Auto) will Output as one of the above, shortest wins.