The content on this page is written in Chinese, and then traslated into English by machine. More accurate traslations are welcome at: https://github.com/wa-lang/man/tree/master/en
Ending's law: "Any application that can be compiled to WebAssembly, will be compiled to WebAssembly eventually."
3.3. Floating point number
Wa-lang currently supports the following types of floating point numbers (both are IEEE 754 standards):
f32: 32-bit floating point numberf64: 64-bit floating point number
Floating point numbers support the following unary operators
-: Get the negative arithmetic value (that is, subtract the operand from 0)
For example:
i: f32 = 1.25
println(-i) //-1.25
Floating point numbers support the following binary arithmetic operations:
+: Add, the two operand types must be consistent, the type of return value is same with operands;-: Minus, the two operand types must be consistent, the type of return value is same with operands;*: Mul, the two operand types must be consistent, the type of return value is same with operands;/: Div, the two operand types must be consistent, the type of return value is same with operands;
For example:
i, j: f64 = 1, 0.5
println(i + j) // 1.5
println(i - j) // 0.5
println(i * j) // 0.5
println(j / i) // 2
Floating point numbers support the following comparison operations:
==: equal. The operands types must be consistent, and the return value is ofbooltype. If the judgment condition is met,truewill be returned, otherwisefalsewill be returned, the same below;!=: not equal;>: greater than;>=: greater than;<: less than;<=: Small equal to.
When using untyped floating-point constants for variable short-declaration, the variable type is f64. The following two ways of writing are equivalent:
f := 1.5
f: f64 = 1.5