本文概述
符号 |
描述 |
+(更多) |
它增加了两个值 |
-(减, 减) |
它减去两个值 |
*(乘法, 倍) |
它将两个值相乘 |
/(除以) |
它用来划分 |
%(模数, 模) |
返回除法运算的余数 |
**(幂运算) |
它执行指数运算 |
F#算术运算符示例
module Arithmetic =
let add (a:int, b:int):int =
a+b
let sub (a:int, b:int):int =
a-b
let mul (a:int, b:int):int =
a*b
let div (a:int, b:int):int =
if b<>0 then
a/b
else 0
let modu (a:int, b:int):int =
a%b
open Arithmetic
let addition = add (10, 10)
let subtraction = sub (50, 20)
let multiplication = mul (10, 10)
let division = div (10, 2)
let modulus = modu (10, 3)
printfn "--------------------Result------------------"
printfn "sum = %d" addition
printfn "subtraction = %d" subtraction
printfn "multiply = %d" multiplication
printfn "division = %d" division
printfn "modulus = %d" modulus
输出:
--------------------Result------------------
sum = 20
subtraction = 30
multiply = 100
division = 5
modulus = 1
F#一元算术运算符
符号 |
描述 |
+(正数) |
它适用于算术表达式。它不会改变价值的迹象 |
-(negative, negation) |
它适用于算术表达式。它改变了价值的象征。 |
F#二进制比较运算符
符号 |
描述 |
=(平等, 等于) |
这不是赋值运算符。它仅用于比较。这是一个通用运算符。 |
>(greater than) |
它是一个通用运算符 |
<(少于) |
它是一个通用运算符 |
> =(大于或等于) |
它是一个通用运算符 |
<=(小于或等于) |
它是一个通用运算符 |
<>(不等于) |
它是一个通用运算符 |
F#比较运算符示例
let comparisionOperator(a:int, b:int) =
if(a<b) then
printfn "A is less than B"
if(a>b) then
printfn "A is greater than B"
if(a=b) then
printfn "A is equal to B"
comparisionOperator (10, 20) // calling of function
输出:
A is less than B
评论前必须登录!
注册