FreeMat: FLOAT Convert to 32-bit Floating Point

FreeMat

- Main Page
- Related Pages

FLOAT Convert to 32-bit Floating Point

Section: Type Conversion Functions

# Usage

Converts the argument to a 32-bit floating point number. The syntax for its use is

       y = float(x)

where `x` is an `n`-dimensional numerical array. Conversion follows the saturation rules. Note that both `NaN` and `Inf` are both preserved under type conversion.

# Example

The following piece of code demonstrates several uses of `float`. First, we convert from an integer (the argument is an integer because no decimal is present):

    --> float(200)

    ans =
     200

In the next example, a double precision argument is passed in

    --> float(400.0)

    ans =
     400

In the next example, a complex argument is passed in.

    --> float(3.0+4.0*i)

    ans =
       3.0000 +  4.0000i

In the next example, a string argument is passed in. The string argument is converted into an integer array corresponding to the ASCII values of each character.

    --> float('helo')

    ans =
     104 101 108 111

In the last example, a cell-array is passed in. For cell-arrays and structure arrays, the result is an error.

    --> float({4})
    Error: Cannot perform type conversions with this type