WolframLang: Force Numerical Result

By Xah Lee. Date: . Last updated: .

(similar idea is “casting”, in many languages.)

Symbolic Result vs Numerical Result

All computation are done symbolically by default, returning symbolic (exact) result. For example, 3/2 return just itself (does not become 1.5). And 6/4 return the rational number 3/2. Another example: 1/2 + 1/3 return 5/6

3/2
(* return itself *)

1/2 + 1/3
(* 5/6 *)

If parts of expression contains approximate number, then the result is approximate.

3/2 + 5/9.
(* return 2.05556 *)

Convert Exact Number to Approximate (Machine Number)

use N[expression] to convert numbers in expression to machine precision numbers.

N[3/2]
(* return 1.5 *)

A common way to use N is via postfix notation, That is, N[expr] is the same as expr//N

x = ((1/2)^5 + (3/2)^2)^3
(* 389017/32768 *)

x //N
(* 11.871856689453125 *)

WolframLang: Number