Float keyword

From Dragon Age Toolset Wiki
Jump to: navigation, search

The float type represents a signed 32-bit floating-point value between -3.402823e38 and 3.402823e38. The default value is 0.0.

Literals

A float literal is a decimal (base 10) number and consists of a string of decimal digits (0-9) followed by a decimal point. Optionally one or more decimal digits (the mantissa) and/or a letter "f" suffix can follow the decimal point.

    // valid float literals
    float fLiteral1 = 1.;
    float fLiteral2 = 1.2;
    float fLiteral3 = 1.f;
    float fLiteral4 = 1.2f;
 
    // invalid float literals
    float fInvalid1 = 1;        // causes "Mismatched type" error
    float fInvalid2 = .1;       // causes "Unknown state in compiler" error
    float fInvalid3 = 1f;       // causes "Parsing variable list" error
    float fInvalid4 = .1f;      // causes "Unknown state in compiler" error

Note that since the decimal point is required even when there is no mantissa the "f" suffix is in fact totally redundant.

Conversion

Explicit

The following functions can be used to convert another data type to a float:

The following functions can be used to convert a float to another data type:

Implicit

If an int and a float are mixed in an arithmetic expression the int is implicitly converted to a float without needing to use the IntToFloat function.

    // addition
    float fResult1 = 32 + 1.0;
 
    // subtraction
    float fResult2 = 32 - 1.0;
 
    // multiplication
    float fResult3 = 32 * 1.0;
 
    // division
    float fResult4 = 32 / 1.0;

This is true whether the values are literals (above), variable values or values returned by functions.

Persistence

The following functions allow a float to exist outside of the scope of the current script by storing it on an object, effect or event:

The following functions allow a location which exist outside of the scope of the current script to be used in the current script by retrieving it from an object, effect or event:

Examples

void main()
{
    // uninitialised: value = 0.0
    float fDefault;
 
    // initialised: value = 42.0
    float fSpecific = 42.0;
}

See Also

PrintFloat