The ChangePrecision module exports a macro @changeprecision T expression that changes the "default" floating-point precision in a given expression to a new floating-point type T.

@changeprecision T expression

Change the "default" precision in the given expression to the floating-point type T.

This changes floating-point literals, integer expressions like 1/3, random-number functions like rand, and matrix constructors like ones to default to the new type T.

For example,

@changeprecision Float32 begin
    x = 7.3
    y = 1/3
    z = rand() .+ ones(3,4)

uses Float32 precision for all of the expressions in begin ... end.