Programming Language Cheat Sheets: Mathematics

Strings Mathematics Operators and Symbols General (Control Flow/Debugging) Dates Objects [Range] New Features Timelines Sections: The Universal Function Library Project: Details Note: UFL: Universal Function Library, a set of around 100-300 standard functions for all programming languages. Languages do not have to implement anything exactly to the UFL specification, it is a guide. See lower down for further details. UFL: (IntNewDemo) [create an int (integer)] AutoHotkey: vNum := 123 [type: Integer] C++: auto vNum = 123 [type: i] [note: 'auto'/'int' resolve to i] C#: var vNum = 123 [type: Int32] [note: 'var'/'int'/'Int32' resolve to Int32] Crystal: vNum = 123 [type: Int32] Excel: 123 [type: 1 (Number)] Excel VBA: vNum = 123 [type: Integer] Go: vNum := 123 [type: int] Java: var vNum = 123 [type: int] [note: 'var'/'int' resolve to int] JavaScript: vNum = 123 [type: Number] [note: a 64-bit float] Kotlin: var vNum = 123 [type: Int] PHP: $vNum = 123 [type: integer] Python: vNum = 123 [type: int] R: vNum = 123 [type: double (class: numeric)] [also: vNum = as.integer(123)] [type (as.integer): integer] Ruby: vNum = 123 [type: Integer] Rust: let vNum = 123 [type: i32] Scala: var vNum = 123 [type: int] [also: var vNum: Int = 123] Swift: var vNum = 123 [type: Int] UFL: (FloatNewDemo) [or DoubleNewDemo][create a float (floating-point number)] AutoHotkey: vNum := 123.456 [type: Float] C++: auto vNum = 123.456 [type: d] [note: 'auto'/'double' resolve to d] C#: var vNum = 123.456 [type: Double] [note: 'var'/'double'/'Double' resolve to Double] Crystal: vNum = 123.456 [type: Float64] Excel: 123.456 [type: 1 (Number)] Excel VBA: vNum = 123.456 [type: Double] Go: vNum := 123.456 [type: float64] Java: var vNum = 123.456 [type: double] [note: 'var'/'double' resolve to double] JavaScript: vNum = 123.456 [type: Number] [note: a 64-bit float] Kotlin: var vNum = 123.456 [type: Double] PHP: $vNum = 123.456 [type: double] Python: vNum = 123.456 [type: float] R: vNum = 123.456 [type: double (class: numeric)] Ruby: vNum = 123.456 [type: Float] Rust: let vNum = 123.456 [type: f64] Scala: var vNum = 123.456 [type: double] [also: var vNum: Double = 123.456] Swift: var vNum = 123.456 [type: Double] UFL: True/False [a Boolean value indicating that something is 'true' or 'false'][see also: IsTruthy/OpTern/OpShortTern/SymCharExclExcl/Array.NewMultiTypeFalsyDemo] AutoHotkey: true/false [type: Integer] [note: case-insensitive] C++: true/false [type: b] C#: true/false [type: Boolean] Crystal: true/false [type: Bool] Excel: TRUE/FALSE [type: 4 (Logical Value)] [note: gets case-corrected by Excel] Excel VBA: True/False [type: Boolean] [note: gets case-corrected by Excel VBA editor] Go: true/false [type: bool] Java: true/false [type: Boolean] JavaScript: true/false [type: boolean] Kotlin: true/false [type: Boolean] PHP: true/false [type: boolean] [note: case-insensitive] Python: True/False [type: bool] R: TRUE/FALSE [type: logical] Ruby: true/false [type: TrueClass/FalseClass] Rust: true/false [type: bool] Scala: true/false [type: boolean] Swift: true/false [type: Bool] UFL: IsTruthy [examples below handle at least string/int/float/bool (i.e. falsy: ""/0/0.0/-0.0/false)][note: other values to consider: NaN, null, empty objects, some objects types][see also: OpTern/OpShortTern/SymCharExclExcl/Array.NewMultiTypeFalsyDemo] AutoHotkey: vIsTruthy := !!vVar [also: vVar ? true : false] [note (both): NaN is considered truthy] C++: vIsTruthy = !!vVar [also: vVar ? true : false] [WARNING (both): "" is considered truthy] [WARNING (both): throw on std::string] [note (both): NaN is considered truthy] C#: vIsTruthy = !((object[])["", 0, 0.0, false]).Contains(vVar) [note: works on negative zero too] [note: NaN is considered truthy] Crystal: vIsTruthy = !["", 0, false].includes?(vVar) [note: works on floats too] [note: NaN is considered truthy] [MAJOR WARNING: in Crystal, only false/nil are considered falsy (e.g. 0 and "" are considered truthy)] Excel: ___ [can use: =AND(A1<>"",IFERROR(A1+0<>0,TRUE),A1<>FALSE)] [can use (but fails on negative zero): =AND(A1<>"",A1<>0,A1<>FALSE)] Excel VBA: vIsTruthy = (vVar <> "") And (vVar <> 0) [note: works on bools/floats too] [note: NaN is considered falsy] Go: vIsTruthy := !slices.Contains([]interface{}{"", 0, 0.0, false}, vVar) [note: works on negative zero too] [note: NaN is considered truthy] Java: vIsTruthy = !List.of("", 0, 0.0, -0.0, false).contains(vVar) [note: NaN is considered truthy] [requires: import java.util.*] [also: vIsTruthy = !Arrays.stream(new Object[]{"", 0, 0.0, -0.0, false}).anyMatch(vVar::equals)] JavaScript: vIsTruthy = !!vVar [also: vVar ? true : false] [note (both): NaN is considered falsy] Kotlin: vIsTruthy = !arrayOf("", 0, 0.0, -0.0, false).contains(vVar) [note: NaN is considered truthy] PHP: $vIsTruthy = !!$vVar [also: $vVar ? true : false] [note (both): NaN is considered truthy] Python: vIsTruthy = not not vVar [also: vIsTruthy = True if vVar else False] [note: NaN is considered truthy] R: vIsTruthy = !vVar %in% list("", 0, FALSE) [also: !is.element(vVar, list("", 0, FALSE))] [note: works on floats too] [note: works on as.integer(vNum) too] [note: NaN is considered truthy] Ruby: vIsTruthy = !["", 0, false].include?(vVar) [note: works on floats too] [note: NaN is considered truthy] [MAJOR WARNING: in Ruby, only false/nil are considered falsy (e.g. 0 and "" are considered truthy)] Rust: ___ Scala: vIsTruthy = !Array("", 0, 0.0, -0.0, false).contains(vVar) [note: NaN is considered truthy] Swift: vIsTruthy = !((vVar is String && vVar as! String == "") || (vVar is Int && vVar as! Int == 0) || (vVar is Double && vVar as! Double == 0.0) || (vVar is Bool && vVar as! Bool == false)) [note: works on negative zero too] [note: NaN is considered truthy] UFL: BoolToStr [or BoolToString][bool to string 'true'/'false' (or 'True'/'False', or 'TRUE'/'FALSE')][see also: String] AutoHotkey: vText := vBool ? "true" : "false" [WARNING: String(True)/String(False) output "1"/"0"] C++: vText = vBool ? "true" : "false" [WARNING: std::to_string(vBool) outputs "1"/"0"] C#: vText = "" + vBool [also: vBool.ToString()] [note: outputs True/False] [WARNING: keywords lower case, output string title case] Crystal: vText = vBool.to_s [note: outputs true/false] Excel: =""&A1 [note: where A1 contains TRUE or FALSE] [note: outputs TRUE/FALSE] Excel VBA: vText = "" & vBool [note: outputs True/False] [also: CStr(vBool)] Go: vText := fmt.Sprintf("%v", vBool) [also: [strconv.FormatBool(vBool)] [note (both): outputs true/false] Java: vText = "" + vBool [note: outputs true/false] [also: String.valueOf(vBool)] [also: Boolean.toString(vBool)] JavaScript: vText = "" + vBool [note: outputs true/false] [also: String(vBool)] Kotlin: vText = "" + vBool [note: outputs true/false] [also: vBool.toString()] PHP: $vText = $vBool ? "true" : "false" [also: $vText = var_export($vBool, true)] [WARNING: strval(true)/strval(false) output "1"/"" (i.e. '1' or a blank string)] Python: vText = str(vBool) [note: outputs True/False] R: vText = paste(vBool) [note: outputs TRUE/FALSE] Ruby: vText = vBool.to_s [note: outputs true/false] Rust: vText = vBool.to_string() [note: outputs true/false] [also: vText = format!("{}", vBool)] Scala: vText = "" + vBool [note: outputs true/false] [also: String.valueOf(vBool)] [also: vBool.toString] Swift: vText = String(vBool) [note: outputs true/false] [also: vBool.description] UFL: StrToBool [or StringToBool][non-blank to true, blank to false] AutoHotkey: ___ [can use: vBool := (vText != "")] C++: ___ [can use: vBool = (vText != "")] C#: ___ [can use: vBool = (vText != "")] Crystal: ___ [can use: vBool = (vText != "")] [MAJOR WARNING: in Crystal, only false/nil are considered falsy (e.g. 0 and "" are considered truthy)] Excel: ___ [can use: =A1<>""] Excel VBA: ___ [can use: vBool = (vText <> "")] Go: ___ [can use: vBool := (vText != "")] Java: ___ [can use: vBool = (vText != "")] JavaScript: ___ [can use: vBool = (vText !== "")] Kotlin: ___ [can use: vBool = (vText != "")] PHP: ___ [can use: $vBool = ($vText != "")] Python: ___ [can use: vBool = (vText != "")] R: ___ [can use: vBool = (vText != "")] Ruby: ___ [can use: vBool = (vText != "")] [MAJOR WARNING: in Ruby, only false/nil are considered falsy (e.g. 0 and "" are considered truthy)] Rust: ___ [can use: vBool = (vText != "")] Scala: ___ [can use: vBool = (vText != "")] Swift: ___ [can use: vBool = (vText != "")] UFL: BoolAsStrToBool [or StrBoolToBool][string to bool, case-insensitive, 'true' to true, anything else to false][WARNING: attempts to cast "false" to boolean often return true (since "false" is a non-blank string)] AutoHotkey: vBool := (StrLower(vText) == "true") [also (case-insensitive): vBool := (vText = "true")] C++: ___ [can use (case-sensitive): vBool = (vText == "true")] [also: vBool = (vText == "true") || (vText == "True") || (vText == "TRUE")] C#: vBool = (vText.ToLower() == "true") [WARNING: vBool.ToString() outputs True (not 'true')] Crystal: vBool = (vText.downcase == "true") Excel: =LOWER(A1)="true" [WARNING: Excel uses TRUE (not 'true')] [note: =A1="true" will also work, since Excel formulae are case-insensitive] Excel VBA: vBool = (LCase(vText) = "true") [WARNING: Excel VBA uses True keyword (not 'true')] Go: vBool := (strings.ToLower(vText) == "true") Java: vBool = (vText.toLowerCase() == "true") JavaScript: vBool = (vText.toLowerCase() === "true") [also: vBool = JSON.parse(vText)] Kotlin: vBool = (vText.lowercase() == "true") PHP: $vBool = (mb_strtolower($vText) == "true") [note: strtolower() will also work] Python: vBool = (vText.lower() == "true") [WARNING: Python uses True (not 'true')] R: vBool = (tolower(vText) == "true") Ruby: vBool = (vText.downcase == "true") Rust: vBool = (vText.to_lowercase() == "true") Scala: vBool = (vText.toLowerCase == "true") Swift: vBool = (vText.lowercased() == "true") UFL: Abs [absolute value] AutoHotkey: Abs C++: abs [also: labs/fabs] C#: Math.Abs Crystal: abs [e.g. vNum.abs] Excel: ABS Excel VBA: Abs Go: math.Abs Java: Math.abs JavaScript: Math.abs Kotlin: Math.abs PHP: abs Python: abs [also: math.fabs] R: abs Ruby: abs [e.g. vNum.abs] Rust: abs Scala: math.abs Swift: abs [also: fabs] UFL: Sign [e.g. returns 1/0/-1][possible implementation: if 0/0.0/-0.0/NaN returns itself, if positive returns 1/1.0, if negative returns -1/-1.0][see also: NumCompare] AutoHotkey: ___ [can use: vSign := ((vNum>0)?1:(vNum<0)?-1:vNum) + vNum*0] C++: ___ [can use: vNum <=> 0] [e.g. int vSign = (int)std::bit_cast<int8_t>(vNum <=> 0)] C#: Math.Sign [e.g. vSign = Math.Sign(vNum)] Crystal: ___ [can use: vSign = vNum <=> 0] Excel: SIGN [e.g. SIGN(A1)] Excel VBA: Sgn [e.g. vSign = Sgn(vNum)] [note: 'Sgn', not 'Sign'] Go: ___ Java: Math.signum [e.g. vSign = Math.signum(vNum)] JavaScript: Math.sign [e.g. vSign = Math.sign(vNum)] Kotlin: kotlin.math.sign [e.g. vSign = kotlin.math.sign(vNum)] [also: Math.signum] PHP: ___ [can use: $vSign = $vNum <=> 0] Python: ___ [can use: vSign = math.copysign(1 if vNum else 0, vNum)] R: sign [e.g. sign(vNum)] Ruby: ___ [can use: vSign = vNum <=> 0] Rust: ___ [can use: vSign = (if (vNum as f64)==0f64 {0f64} else {1f64}).copysign(vNum as f64)] [can use (for ints): signum] [e.g. (vNum).signum()] [WARNING: for floats, signum returns 1 or -1, not 0] Scala: math.signum [e.g. vSign = math.signum(vNum)] Swift: signum [e.g. vNum.signum()] [note: floats lack a signum method] UFL: SignNoZero [or SignPsvNgv][e.g. returns 1/-1][like Sign except 0's become 1 or -1][possible implementation: if positive/0/0.0 returns 1, if negative/-0.0 returns -1] AutoHotkey: ___ C++: ___ [can use: std::copysign(1.0, vNum)] C#: ___ Crystal: ___ Excel: ___ Excel VBA: ___ Go: ___ [can use: math.Copysign(1.0, vNum)] Java: ___ [can use: Math.copySign(1.0, vNum)] JavaScript: ___ Kotlin: ___ [can use: Math.copySign(1.0, vNum)] [also: (1.0).withSign(vNum)] [requires (withSign): import kotlin.math.withSign] PHP: ___ Python: ___ [can use: math.copysign(1, vNum)] [e.g. math.copysign(1, 0) and math.copysign(1, -0.0) return 1.0 and -1.0 respectively] [requires: import math] R: ___ [can use: vSign = if (1/vNum > 0) 1 else -1] [note: 1/0 (ints and floats) returned Inf] Ruby: ___ Rust: ___ [can use (for floats): signum] [WARNING: for int 0, signum returns 0, not 1] Scala: ___ [can use: math.copySign(1.0, vNum)] Swift: ___ [can use: vSign = ((vNum).sign == .plus) ? 1 : -1] [can use: copysign(1.0, vNum)] [requires (copysign): import Foundation] UFL: SignBit [(or IsNgv)][e.g. returns 0/1][like SignPsvNgv except returns 0/1 (not 1/-1)][possible implementation: if negative/-0.0 returns 1, if positive/0/0.0 returns 0] AutoHotkey: ___ C++: std::signbit C#: ___ Crystal: ___ Excel: ___ Excel VBA: ___ [can use: LSet and Byte/TDouble/TArray types (i.e. number to bit representation)] Go: math.Signbit [note (Signbit): returns true/false] [also: vSignBit = max(-math.Copysign(1.0, vNum), 0)] [note: Go lacks a ternary operator] Java: ___ [can use: vSignBit = (Math.copySign(1.0, vNum) > 0) ? 0 : 1] JavaScript: ___ Kotlin: ___ [can use: vSignBit = if (Math.copySign(1.0, vNum) > 0) 0 else 1] PHP: ___ Python: [can use: 0 if (math.copysign(1, vNum) > 0) else 1] [requires: import math] R: ___ [can use: vSignBit = if (1/vNum > 0) 0 else 1] [note: 1/0 (ints and floats) returned Inf] Ruby: ___ Rust: ___ [can use: is_negative/is_sign_negative for ints/floats respectively] Scala: ___ [can use: vSignBit = if(math.copySign(1.0, vNum) > 0) 0 else 1)] Swift: ___ [can use: vSignBit = (copysign(1.0, vNum) > 0) ? 0 : 1] [requires (copysign): import Foundation] UFL: Pow [power (exponent)] AutoHotkey: ___ [can use: **] C++: pow C#: Math.Pow Crystal: ___ [can use: **] Excel: POWER [can use: ^] [WARNING: ^ is often used as bitwise-xor] Excel VBA: WorksheetFunction.Power [can use: ^] [WARNING: ^ is often used as bitwise-xor] Go: math.Pow Java: Math.pow JavaScript: Math.pow [can use: **] Kotlin: Math.pow PHP: pow [can use: **] Python: pow [also: math.pow/operator.pow] [WARNING: math.pow treats (converts) inputs as floats (rather than maintain any integers)] [can use: **] R: ___ [can use: **] [also: ^] Ruby: ___ [can use: **] Rust: pow [also: powi/powf] Scala: math.pow Swift: pow [requires: import Foundation] UFL: Sqrt/(Cbrt) [square root/cube root] AutoHotkey: Sqrt/___ C++: sqrt/cbrt C#: Math.Sqrt/Math.Cbrt Crystal: Math.sqrt/Math.cbrt Excel: SQRT/___ Excel VBA: Sqr/___ [note: 'Sqr', not 'Sqrt'] Go: math.Sqrt/math.Cbrt Java: Math.sqrt/Math.cbrt JavaScript: Math.sqrt/Math.cbrt Kotlin: Math.sqrt/Math.cbrt PHP: sqrt/___ Python: math.sqrt/math.cbrt R: sqrt/___ Ruby: Math.sqrt/Math.cbrt Rust: sqrt/cbrt Scala: math.sqrt/math.cbrt Swift: sqrt/cbrt [also: squareRoot] UFL: Round [round to the nearest integer][see also: RoundDP][note: 0.5 rounds to 1, -0.5 rounds to -1] AutoHotkey: Round [e.g. vInt := Round(vNum)] C++: round [e.g. vFloat = round(vNum)] C#: Math.Round [e.g. vFloat = Math.Round(vNum)] Crystal: round [e.g. vFloat = vNum.round] Excel: ROUND [e.g. ROUND(A1,0)] Excel VBA: Round [e.g. vFloat = WorksheetFunction.Round(vNum, 0)] [note: returns a float] [WARNING (built-in Round, not WorksheetFunction): uses bankers' rounding, and doesn't handle negative DP] Go: math.Round [e.g. vFloat := math.Round(vNum)] [also: math.RoundToEven] Java: ___ [WARNING: Math.round/Math.rint (to nearest even integer in tiebreaks) both give unusual results, particularly when handling tiebreaks e.g. 0.5] [can use: toBigDecimal/String.format/DecimalFormat using RoundingMode.HALF_UP and/or Locale.ENGLISH] JavaScript: Math.round [e.g. vFloat = Math.round(vNum)] Kotlin: ___ [WARNING: kotlin.math.round/roundToLong/roundToInt/Math.Round all give unusual results, particularly when handling tiebreaks e.g. 0.5] [can use: toBigDecimal/String.format/DecimalFormat using RoundingMode.HALF_UP and/or Locale.ENGLISH] PHP: round [e.g. $vFloat = round($vNum)] Python: round [e.g. vInt = round(vNum)] R: round [e.g. vFloat = round(vNum)] [also (significant figures): signif] Ruby: round [e.g. vInt = vNum.round] Rust: round [e.g. vFloat = vNum.round()] Scala: math.round [WARNING: for values ending 0.5: rounds up (towards positive infinity)] Swift: rounded [e.g. vFloat = vNum.rounded()] [requires (round/nearbyint/rint): import Foundation] [WARNING: rint: to nearest even integer in tiebreaks] UFL: RoundDP [round to n decimal places][see also: Round/Format][e.g. 123.456 is 123.46 (2dp), and 100 ('-2dp')][functions handle 'negative' decimal places unless stated] AutoHotkey: Round [e.g. vText := Round(vNum, vDP)] [also: Format] [note: returns a string if DP >= 1, else an int (if DP positive/0/omitted)] C++: std::format [e.g. vText = std::format("{:."+std::to_string(vDP)+"f}", vNum)] [requires: #include <format>] C#: Math.Round [e.g. vFloat = Math.Round(vNum, vDP)] [note: returns a float, doesn't handle negative DP] Crystal: round [e.g. vFloat = vNum.round(vDP)] [note: returns a float] [note: handles positive/0/negative/omitted DP] Excel: ROUND [e.g. ROUND(A1,2)] Excel VBA: Round [e.g. vFloat = WorksheetFunction.Round(vNum, vDP)] [note: returns a float, handles positive/0/negative DP, can't omit DP] [WARNING (built-in Round, not WorksheetFunction): uses bankers' rounding, and throws for negative DP] Go: fmt.Sprintf [e.g. vText := fmt.Sprintf("%."+strconv.Itoa(vDP)+"f", vNum)] Java: ___ [WARNING: Math.round/Math.rint (to nearest even integer in tiebreaks) both give unusual results, particularly when handling tiebreaks e.g. 0.5] [can use: toBigDecimal/String.format/DecimalFormat using RoundingMode.HALF_UP and/or Locale.ENGLISH] JavaScript: toFixed [e.g. vText = vNum.toFixed(vDP)] [note: throws if DP negative] Kotlin: ___ [WARNING: kotlin.math.round/roundToLong/roundToInt/Math.Round all give unusual results, particularly when handling tiebreaks e.g. 0.5] [can use: toBigDecimal/String.format/DecimalFormat using RoundingMode.HALF_UP and/or Locale.ENGLISH] PHP: round [e.g. $vFloat = round($vNum, $vDP)] [note: returns a float, handles positive/0/negative/omitted DP] Python: round [e.g. vFloat = round(vNum, vDP)] [note: returns a float if DP specified (positive/0/negative), else an int (if DP omitted)] R: round [e.g. vFloat = round(vNum, vDP)] [note: returns a float, handles positive/0/negative/omitted DP] Ruby: round [e.g. vFloat = vNum.round(vDP)] [note: returns a float if DP is positive, and Num is a float, else an int] [note: handles positive/0/negative/omitted DP] Rust: ___ [e.g. vText = format!("{:.1$}", vNum, vDP)] Scala: ___ [WARNING: math.round/math.rint both give unusual results] [note: math.rint rounds tiebreaks towards the even integer] Swift: ___ [e.g. vText = String(format:"%."+String(vDP)+"f", vNum)] [requires (format): import Foundation] [note: doesn't handle negative DP] UFL: Ceil [round up (towards +infinity)] AutoHotkey: Ceil C++: ceil C#: Math.Ceiling Crystal: ceil [e.g. vNum.ceil] Excel: CEILING.PRECISE [note: a formula for Ceil: -INT(-A1)] [WARNING: Excel's INT function works like a floor function, it always rounds down, towards -infinity (usually Int functions round towards 0, just like Excel's TRUNC function)] [WARNING: Excel's CEILING is unusual, it rounds away from 0 (it is usual to round towards +infinity)] Excel VBA: WorksheetFunction.Ceiling_Precise [note: a formula for Ceil: -Int(-vNum)] [WARNING: Excel VBA's Int function works like a floor function, it always rounds down, towards -infinity (usually Int functions round towards 0, just like Excel VBA's Fix function)] Go: math.Ceil Java: Math.ceil JavaScript: Math.ceil Kotlin: Math.ceil PHP: ceil Python: math.ceil R: ceiling Ruby: ceil [e.g. vNum.ceil] Rust: ceil Scala: math.ceil Swift: ceil UFL: Floor [round down (towards -infinity)] AutoHotkey: Floor C++: floor C#: Math.Floor Crystal: floor [e.g. vNum.floor] Excel: FLOOR.PRECISE [also: INT] [WARNING: Excel's INT function works like a floor function, it always rounds down, towards -infinity (usually Int functions round towards 0, just like Excel's TRUNC function)] [WARNING: Excel's FLOOR is unusual, it rounds towards 0 (it is usual to round towards -infinity)] Excel VBA: WorksheetFunction.Floor_Precise [also: Int] [WARNING: Excel VBA's Int function works like a floor function, it always rounds down, towards -infinity (usually Int functions round towards 0, just like Excel VBA's Fix function)] Go: math.Floor Java: Math.floor JavaScript: Math.floor Kotlin: Math.floor PHP: floor Python: math.floor R: floor Ruby: floor [e.g. vNum.floor] Rust: floor Scala: math.floor Swift: floor UFL: Trunc [truncate (round towards zero) (remove the fractional part)][see also: FloatToInt] AutoHotkey: Integer C++: trunc C#: Math.Truncate Crystal: to_i [e.g. vNum.to_i] Excel: TRUNC [WARNING: Excel's INT function works like a floor function, it always rounds down (logically it should work just like Excel's TRUNC function)] Excel VBA: Fix [WARNING: Excel VBA's Int function works like a floor function, it always rounds down (logically it should work just like Excel VBA's Fix function)] Go: math.Trunc Java: int [e.g. (int)vFloat)] [also: Double.valueOf(vFloat).intValue()] JavaScript: Math.trunc Kotlin: kotlin.math.truncate PHP: intval Python: int [also: math.trunc] R: trunc [also: as.integer] Ruby: truncate [e.g. vNum.truncate] [also: vNum.to_i] Rust: trunc Scala: toInt [e.g. vFloat.toInt] [also: vFloat.toInt.toDouble] Swift: trunc [e.g. trunc(vNum)] [also: Int] [requires (trunc): import Foundation] UFL: Frac [or Fract][number: get the fractional part (e.g. 2.9 to 0.9, e.g. -2.9 to -0.9), e.g. x = trunc(x) + frac(x)] AutoHotkey: ___ [can use: Mod(vNum, 1)] [also: vNum-Integer(vNum)] C++: ___ [can use: fmod(vNum, 1)] [note: throws if use %] C#: ___ [can use: vNum % 1] Crystal: ___ [can use: vNum.remainder(1)] [also: vNum-vNum.to_i] [also: vNum.modulo(vNum>0?1: -1)] [WARNING: Ruby's modulo and % are FloorMod, e.g. -2.9 % 1 = 0.1, but we want -0.9] Excel: ___ [can use: MOD(A1,1)] [also: A1-TRUNC(A1)] Excel VBA: ___ [can use: vNum-Fix(vNum)] [WARNING: don't use Mod operator, Excel VBA's Mod rounds inputs to the nearest integer] Go: ___ [can use: math.Mod(vNum, 1)] [also: vNum - math.Trunc(vNum)] [also: _, vFrac := math.Modf(vNum)] Java: ___ [can use: vNum % 1] JavaScript: ___ [can use: vNum % 1] [also: vNum-Math.trunc(vNum)] Kotlin: ___ [can use: vNum % 1] PHP: ___ [can use: fmod($vNum, 1)] [note: throws if use %] Python: ___ [can use: math.fmod(vNum, 1)] [WARNING: Python's % is a floor mod, e.g. -2.9 % 1 = 0.1, but we want -0.9] R: ___ [can use: vNum-trunc(vNum)] [also: vNum-as.integer(vNum)] [WARNING: R's %% is a floor mod, e.g. -2.9 %% 1 = 0.1, but we want -0.9] Ruby: ___ [can use: vNum.remainder(1)] [also: vNum-vNum.to_i] [also: vNum.modulo(vNum>0?1:-1)] [WARNING: Ruby's modulo and % are FloorMod, e.g. -2.9 % 1 = 0.1, but we want -0.9] Rust: fract Scala: ___ [can use: vNum % 1] Swift: ___ [can use: vNum.truncatingRemainder(dividingBy:1)] [note: throws if use %] UFL: Number [or StrToNumber][to number (integer/float)][i.e. int-like to int, float-like to float] AutoHotkey: Number C++: ___ C#: ___ Crystal: ___ Excel: N [e.g. N(A1)] Excel VBA: ___ Go: ___ Java: ___ JavaScript: Number [note: this is really a ToFloat function, i.e. string to 64-bit float] Kotlin: ___ PHP: ___ Python: ___ R: as.numeric [note: this is really a ToFloat function, i.e. string to float] Ruby: ___ Rust: ___ Scala: ___ Swift: ___ UFL: StrToInt [or StringToInteger][string to integer][note: floats as strings are truncated (rounded towards zero) (or if throws, stated below)] AutoHotkey: Integer [e.g. vNum := Integer(vText)] [note: accepts float-like input string] C++: std::stoi [e.g. vNum = std::stoi(vText)] [note: accepts float-like input string] C#: Int32.Parse [e.g. vNum = Int32.Parse(vText)] [also: Int64.Parse] [WARNING: fails on float-like input string] Crystal: to_i [e.g. vNum = vText.to_i] [WARNING: fails on float-like input string] Excel: TRUNC [e.g. TRUNC(A1)] [WARNING: Int floors (always rounds down)] [note: accepts float-like input string] Excel VBA: CInt [e.g. vNum = CInt(vText)] [also: CLng/CLngLng/CLngPtr] [note: accepts float-like input string] Go: strconv.Atoi [e.g. vNum, vErr := strconv.Atoi(vText)] [also: vNum, vErr := strconv.ParseInt(vText, 10, 64)] [WARNING (both): fails on float-like input string] [WARNING (both): on failure, sets error value to non-nil, but doesn't throw (as is standard in Go)] Java: Integer.parseInt [e.g. vNum = Integer.parseInt(vText)] [WARNING: fails on float-like input string] JavaScript: parseInt [e.g. vNum = parseInt(vText)] [note: accepts float-like input string] Kotlin: toInt [e.g. vNum = vText.toInt()] [WARNING: fails on float-like input string] PHP: intval [e.g. $vNum = intval($vText)] [also: $vNum = (int)$vText] [note: accepts float-like input string] Python: int [e.g. vNum = int(vText)] [WARNING: fails on float-like input string] R: as.integer [e.g. vNum = as.integer(vText)] [e.g. also: vNum = as.numeric(as.integer(vText))] [note: accepts float-like input string] Ruby: to_i [e.g. vNum = vText.to_i] [note: accepts float-like input string] Rust: parse [e.g. vNum: i32 = vText.parse().unwrap()] [WARNING: fails on float-like input string] Scala: toInt [e.g. vNum = vText.toInt] [WARNING: throws on float-like input string] Swift: Int [e.g. vNum = Int(vText)!] [WARNING: fails on float-like input string] UFL: StrToIntOrDefault [string to integer (or default)][note: floats as strings are truncated (rounded towards zero) (or if throws, stated below)][e.g. try: vText = "a"][e.g. sort strings as ints] AutoHotkey: ___ C++: ___ C#: TryParse [e.g. vBool = int.TryParse(vText, out vNum)] Crystal: ___ Excel: ___ Excel VBA: ___ Go: strconv.Atoi [e.g. vNum, vErr := strconv.Atoi(vText)] [note: returns 2 params (0 and error message) if fails] [WARNING: can't use as direct return value] Java: ___ JavaScript: parseInt [e.g. vNum = parseInt(vText)] [note: returns NaN if fails] Kotlin: ___ PHP: ___ [can use: $vNum = intval($vText)] [note: returns 0 if fails] Python: ___ R: as.integer [e.g. vNum = as.integer(vText)] [e.g. also: vNum = as.numeric(as.integer(vText))] [note: returns NA if fails] Ruby: ___ [can use: vNum = vText.to_i] [note: returns 0 if fails] Rust: parse [e.g. vNum: i32 = vText.parse().unwrap_or(vDefault)] Scala: toIntOption [e.g. vNum = vText.toIntOption.getOrElse(vDefault)] Swift: Int [e.g. vNum = Int(vText) ?? vDefault] UFL: FloatToInt [or DoubleToInt/FloatToInteger/DoubleToInteger][float to integer, double to integer][note: floats are truncated (rounded towards zero)][see also: Trunc] AutoHotkey: Integer [e.g. vNum := Integer(vFloat)] C++: int [e.g. vNum = (int)vFloat] C#: int [e.g. vNum = (int)vFloat] [also: Math.Truncate] Crystal: to_i [e.g. vNum = vFloat.to_i] Excel: TRUNC [e.g. TRUNC(A1)] [WARNING: INT floors (always rounds down)] Excel VBA: CInt [e.g. vNum = CInt(vFloat)] [also: Fix] Go: int [e.g. vNum := int(vFloat)] Java: int [e.g. vNum = (int)vFloat] [also: Double.valueOf(vFloat).intValue()] JavaScript: parseInt [e.g. vNum = parseInt(vFloat)] [also: Math.trunc] Kotlin: toInt [e.g. vNum = vFloat.toInt()] [also: kotlin.math.truncate] PHP: intval [e.g. $vNum = intval($vFloat)] [also: $vNum = (int)$vFloat] Python: int [e.g. vNum = int(vFloat)] [also: math.trunc] R: as.integer [e.g. vNum = as.integer(vFloat)] [e.g. also: vNum = as.numeric(as.integer(vFloat))] [also: trunc] Ruby: to_i [e.g. vNum = vFloat.to_i] Rust: i32 [e.g. vNum = vFloat as i32] [also: trunc] Scala: toInt [e.g. vFloat.toInt] [also: toLong] Swift: Int [e.g. vNum = Int(vFloat)] [also: trunc] [requires (trunc): import Foundation] UFL: StrToFloat [or StrToDouble/StringToFloat/StringToDouble][string to float, string to double] AutoHotkey: Float [e.g. vNum := Float(vText)] C++: std::stod [e.g. vNum = std::stod(vText)] C#: Double.Parse [e.g. vNum = Double.Parse(vText)] Crystal: to_f [e.g. vNum = vText.to_f] Excel: ___ [can use: A1+0] Excel VBA: CDbl [e.g. vNum = CDbl(vText)] [also: CSng/CDec/CVar] Go: strconv.ParseFloat [e.g. vNum, vErr := strconv.ParseFloat(vText, 64)] Java: Double.parseDouble [e.g. vNum = Double.parseDouble(vText)] JavaScript: parseFloat [e.g. vNum = parseFloat(vText)] [also: vNum = Number(vText)] Kotlin: toDouble [e.g. vNum = vText.toDouble()] PHP: floatval [e.g. $vNum = floatval($vText)] [also: $vNum = (float)$vText] [note: '(double)' is an alias of '(float)'] Python: float [e.g. vNum = float(vText)] R: as.numeric [e.g. vNum = as.numeric(vText)] [also: as.double] Ruby: to_f [e.g. vNum = vText.to_f] Rust: parse [e.g. vNum: f64 = vText.parse().unwrap()] Scala: toDouble [e.g. vNum = vText.toDouble] Swift: Double [e.g. vNum = Double(vText)!] UFL: StrToFloatOrDefault [string to float (or default), string to double (or default)][e.g. try: vText = "a"][e.g. sort floats as ints] AutoHotkey: ___ C++: ___ C#: TryParse [e.g. vBool = double.TryParse(vText, out vNum)] Crystal: ___ Excel: ___ Excel VBA: ___ Go: strconv.ParseFloat [e.g. vNum, vErr := strconv.ParseFloat(vText, 64)] [note: returns 2 params (0.0 and error message) if fails] [WARNING: can't use as direct return value] [note: Go Playground prints '0' not '0.0'] Java: ___ JavaScript: parseFloat [e.g. vNum = parseFloat(vText)] [note: returns NaN if fails] Kotlin: ___ PHP: ___ [can use: $vNum = floatval($vText)] [note: returns 0.0 if fails] Python: ___ R: as.numeric [e.g. vNum = as.numeric(vText)] [note: returns NA if fails] Ruby: ___ [can use: vNum = vText.to_f] [note: returns 0.0 if fails] Rust: parse [e.g. vNum: f64 = vText.parse().unwrap_or(vDefault)] Scala: toDoubleOption [e.g. vNum = vText.toDoubleOption.getOrElse(vDefault)] Swift: Double [e.g. vNum = Double(vText) ?? vDefault] UFL: IntToFloat [or IntToDouble/IntegerToFloat/IntegerToDouble][integer to float, integer to double] AutoHotkey: Float [e.g. vNum := Float(vInt)] [also: vNum := vInt + 0.0] C++: double [e.g. vNum = (double)vInt] C#: double [e.g. vNum = (double)vInt] Crystal: to_f [e.g. vNum = vInt.to_f] Excel: ___ [can use: A1] [also: A1+0] Excel VBA: CDbl [e.g. vNum = CDbl(vInt)] Go: float64 [e.g. vNum := float64(vInt)] Java: double [e.g. vNum = (double)vInt] JavaScript: ___ [can use: vNum = vInt] [note: JavaScript stores ints/floats as 64-bit floats (as doubles)] Kotlin: toDouble [e.g. vNum = vInt.toDouble()] PHP: floatval [e.g. $vNum = floatval($vInt)] [also: $vNum = (float)$vInt] [note: '(double)' is an alias of '(float)'] Python: float [e.g. vNum = float(vInt)] R: as.numeric [e.g. vNum = as.numeric(vText)] [also: as.double] Ruby: to_f [e.g. vNum = vInt.to_f] Rust: f64 [e.g. vNum = vInt as f64] Scala: toDouble [e.g. vNum = vInt.toDouble] Swift: Double [e.g. vNum = Double(vInt)] UFL: BoolToInt [true to 1, false to 0][e.g. approaches: int(b), (int)b, b+0, b?1:0, map(false:0,true:1)[b]] AutoHotkey: Integer [e.g. vNum := Integer(vBool)] [also: vNum := vBool] [also: vNum := vBool + 0] [also: vNum := vBool ? 1 : 0] [note: no bool type: true = 1, false = 0] C++: int [e.g. vNum = (int)vBool] [also: vNum = vBool + 0] [also: vNum = vBool ? 1 : 0] C#: ___ [can use: vNum = vBool ? 1 : 0] Crystal: ___ [can use: vNum = vBool ? 1 : 0] Excel: N [e.g. N(A1)] [also: A1+0] Excel VBA: CInt [e.g. vNum = CInt(vBool)] Go: ___ [can use: vNum := map[bool]int{false: 0, true: 1}[vBool]] [note: Go lacks a ternary operator] Java: ___ [can use: vNum = vBool ? 1 : 0] JavaScript: Number [e.g. vNum = Number(vBool)] [also: vNum = vBool + 0] [also: vNum = vBool ? 1 : 0] [WARNING: parseInt returns NaN if passed a bool] Kotlin: ___ [can use: vNum = if (vBool) 1 else 0] PHP: intval [e.g. $vNum = intval($vBool)] [also: $vNum = $vBool + 0] [also: $vNum = $vBool ? 1 : 0] Python: int [e.g. vNum = int(vBool)] [also: vNum = vBool + 0] R: ___ [e.g. vNum = vBool + 0] [e.g. vNum = as.numeric(vBool)] [e.g. vNum = if (vBool) 1 else 0] Ruby: ___ [can use: vNum = vBool ? 1 : 0] Rust: i32 [e.g. vNum = vBool as i32] [also: vNum = if vBool {1} else {0}] Scala: ___ [can use: vNum = if(vBool) 1 else 0] Swift: ___ [can use: vNum = vBool ? 1 : 0] UFL: IntToBool [non-zero to true, 0 to false][e.g. approaches: bool(n), (bool)n, !!n, n!=0, n?true:false] AutoHotkey: ___ [can use: vBool := !!vNum] [also: vBool := (vNum != 0)] [also: vBool := vNum ? true : false] [note: no bool type: true = 1, false = 0] C++: bool [e.g. vBool = (bool)vNum] [also: vBool = !!vNum] [also: vBool = (vNum != 0)] [also: vBool = vNum ? true : false] C#: ___ [can use: vBool = (vNum != 0)] Crystal: ___ [can use: vBool = (vNum != 0)] [MAJOR WARNING: in Crystal, only false/nil are considered falsy (e.g. 0 and "" are considered truthy)] Excel: ___ [can use: A1<>0] [also: IF(A1,TRUE,FALSE)] [also: NOT(NOT(A1))] Excel VBA: CBool [e.g. vBool = CBool(vNum)] Go: ___ [can use: vBool := (vNum != 0)] Java: ___ [can use: vBool = (vNum != 0)] JavaScript: Boolean [e.g. vBool = Boolean(vNum)] [also: vBool = !!vNum] [also: vBool = (vNum != 0)] [also: vBool = vNum ? true : false] [WARNING: don't use 'new': new Boolean(vNum)] Kotlin: ___ [can use: vBool = (vNum != 0)] PHP: boolval [e.g. $vBool = boolval($vNum)] [also: $vBool = !!$vNum] [also: $vBool = ($vNum != 0)] [also: $vBool = $vNum ? true : false] Python: bool [e.g. vBool = bool(vNum)] [also: vBool = (vNum != 0)] [also: vBool = not not vNum] [also: True if vNum else False] R: as.logical [e.g. vBool = as.logical(vNum)] [also: vBool = !!vNum] [also: vBool = (vNum != 0)] Ruby: ___ [can use: vBool = (vNum != 0)] [MAJOR WARNING: in Ruby, only false/nil are considered falsy (e.g. 0 and "" are considered truthy)] [also: vBool = !vNum.zero?] [WARNING: zero? and nonzero? are not opposites] Rust: ___ [can use: vBool = (vNum != 0)] [note: it appears that Rust actively prohibits using '(vNum as bool)', otherwise it would be valid] Scala: ___ [can use: vBool = (vNum != 0)] Swift: ___ [can use: vBool = (vNum != 0)] UFL: Log [base must be specified unless stated][WARNING: bases 10 and e (e=2.7182818284...) are both common default bases] AutoHotkey: ___ [WARNING: Log uses base 10] C++: ___ [WARNING: log uses base e] C#: Math.Log [WARNING: uses base e if base omitted] Crystal: Math.log [WARNING: uses base e if base omitted] Excel: LOG [WARNING: uses base 10 if base omitted] Excel VBA: WorksheetFunction.Log [WARNING: uses base 10 if base omitted] Go: ___ [WARNING: math.Log uses base e] Java: ___ [WARNING: Math.log uses base e] JavaScript: ___ [WARNING: Math.log uses base e] Kotlin: kotlin.math.log [note: base must be specified] [also: Math.log] [WARNING: Math.log uses base e] PHP: log [WARNING: uses base e if base omitted] Python: math.log [WARNING: uses base e if base omitted] R: log [WARNING: uses base e if base omitted] Ruby: Math.log [WARNING: uses base e if base omitted] Rust: log [note: base must be specified] Scala: ___ [WARNING: math.log uses base e] Swift: ___ [WARNING: log uses base e] [requires: import Foundation] [note: number must be a float] UFL: Ln/Log10/Log2 [log using base e/10/2] AutoHotkey: Ln/Log/___ C++: log/log10/log2 C#: Math.Log/Math.Log10/Math.Log2 [note: Math.Log: can specify base] Crystal: Math.log/Math.log10/Math.log2 Excel: LN/LOG10/___ [note: LOG: uses base 10 if base omitted] Excel VBA: Log/WorksheetFunction.Log10/___ [WARNING: WorksheetFunction.Log is base 10 (if base omitted), Excel VBA's Log is base e] Go: math.Log/math.Log10/math.Log2 Java: Math.log/Math.log10/___ JavaScript: Math.log/Math.log10/Math.log2 Kotlin: kotlin.math.ln/kotlin.math.log10/kotlin.math.log2 [also: Math.log/Math.log10/Math.log2] [note: Math.log uses base e] PHP: log/log10/___ [note: log: can specify base] Python: math.log10/math.log/math.log2 [note: math.log: can specify base] R: log/log10/log2 [note: log: can specify base] Ruby: Math.log/Math.log10/Math.log2 Rust: ln/log10/log2 Scala: math.log/math.log10/___ Swift: log/log10/log2 [requires: import Foundation] [note: number must be a float] UFL: Exp [e to the power of a number (e=2.718...)][Euler's number (pronounced 'oiler')] AutoHotkey: Exp C++: exp C#: Math.Exp Crystal: Math.exp Excel: EXP Excel VBA: Exp Go: math.Exp Java: Math.exp JavaScript: Math.exp Kotlin: Math.exp PHP: exp Python: math.exp R: exp Ruby: Math.exp Rust: exp Scala: math.exp Swift: exp UFL: Clamp [clamp a number (inclusive end), e.g. volume 0-100, e.g. RGB 0-255][equivalent to obtaining the median of 3 numbers] AutoHotkey: ___ [can use (max/min): vNumNew := Max(vMin, Min(vNum, vMax))] C++: std::clamp [e.g. vNumNew = std::clamp(vNum, vMin, vMax)] C#: Math.Clamp [e.g. vNumNew = Math.Clamp(vNum, vMin, vMax)] Crystal: clamp [e.g. vNumNew = vNum.clamp(vMin, vMax)] [also (median): [vNum, vMin, vMax].sort[1]] Excel: ___ [can use (median): MEDIAN(A1,vMin,vMax)] Excel VBA: ___ [can use (median): vNumNew = WorksheetFunction.Median(vNum, vMin, vMax)] Go: ___ [can use (max/min): vNumNew := math.Max(vMin, math.Min(vNum, vMax))] Java: ___ [can use (median): int vNumNew = Arrays.stream(new int[]{vNum, vMin, vMax}).sorted().toArray()[1]] [requires: import java.util.*] JavaScript: ___ [can use (median): vNumNew = [vNum, vMin, vMax].sort((v1,v2)=>v1-v2)[1]] Kotlin: ___ [can use (median): vNumNew = arrayOf(vNum, vMin, vMax).sorted()[1]] PHP: ___ [can use (max/min): $vNumNew = max($vMin, min($vNum, $vMax))] Python: ___ [can use (median): vNumNew = statistics.median([vNum, vMin, vMax])] [also (median): vNumNew = sorted([vNum, vMin, vMax])[1]] [requires (statistics.median): import statistics] R: ___ [can use (median): vNumNew = median(c(vNum, vMin, vMax))] Ruby: clamp [e.g. vNumNew = vNum.clamp(vMin, vMax)] [also (median): [vNum, vMin, vMax].sort[1]] Rust: clamp [e.g. vNumNew = vNum.clamp(vMin, vMax)] Scala: ___ [can use (median): vNumNew = Array(vNum, vMin, vMax).sorted.toList(1)] Swift: ___ [can use (median): vNumNew = [vNum, vMin, vMax].sorted()[1]] [note: Swift has clamped for ranges] UFL: Between [a <= x <= b][is number between limits (inclusive end)][see also: StrBetween/BetweenIfDemo] AutoHotkey: ___ C++: ___ [can use: std::clamp(vNum, vMin, vMax) == vNum] C#: ___ [can use: Math.Clamp(vNum, vMin, vMax) == vNum] Crystal: ___ [can use: (vMin..vMax) === vNum] [also: (vMin..vMax).includes?(vNum)] Excel: ___ [can use: MEDIAN(A1,vMin,vMax)=A1] Excel VBA: ___ [can use: WorksheetFunction.Median(vNum, vMin, vMax) = vNum] Go: ___ Java: ___ JavaScript: ___ Kotlin: ___ PHP: ___ Python: ___ [can use: statistics.median([vNum, vMin, vMax]) == vNum] [requires: import statistics] R: ___ [can use (ints): vNum %in% vMin:vMax] [can use (median): median(c(vNum, vMin, vMax)) == vNum] Ruby: between [e.g. vNum.between?(vMin, vMax)] [also: (vMin..vMax) === vNum] [also: (vMin..vMax).cover?(vNum)] [also: (vMin..vMax).include?(vNum)] Rust: ___ [can use: vNum.clamp(vMin, vMax) == vNum] Scala: ___ Swift: ___ UFL: (BetweenUntil) [a <= x < b][is number between limits (exclusive end)][see also: StrBetweenUntil] AutoHotkey: ___ C++: ___ C#: ___ Crystal: ___ [can use: (vMin...vMax) === vNum] [also: (vMin...vMax).includes?(vNum)] Excel: ___ Excel VBA: ___ Go: ___ Java: ___ JavaScript: ___ Kotlin: ___ PHP: ___ Python: ___ R: ___ Ruby: ___ [can use: (vMin...vMax) === vNum] [also: (vMin...vMax).cover?(vNum)] [also: (vMin...vMax).include?(vNum)] Rust: ___ Scala: ___ Swift: ___ UFL: (BetweenIfDemo) [a <= x <= b][is number between limits (inclusive end)] AutoHotkey: if (vMin <= vNum && vNum <= vMax) [note: parentheses unnecessary] C++: if (vMin <= vNum && vNum <= vMax) C#: if (vMin <= vNum && vNum <= vMax) Crystal: if (vMin <= vNum && vNum <= vMax) [note: parentheses unnecessary] Excel: ___ [can use: AND(vMin<=A1,A1<=vMax)] Excel VBA: If (vMin <= vNum And vNum <= vMax) Then Go: if vMin <= vNum && vNum <= vMax { Java: if (vMin <= vNum && vNum <= vMax) JavaScript: if (vMin <= vNum && vNum <= vMax) Kotlin: if (vMin <= vNum && vNum <= vMax) PHP: if ($vMin <= $vNum && $vNum <= $vMax) Python: if (vMin <= vNum and vNum <= vMax): [note: parentheses unnecessary] R: if (vMin <= vNum && vNum <= vMax) Ruby: if (vMin <= vNum && vNum <= vMax) [note: parentheses unnecessary] Rust: if (vMin <= vNum && vNum <= vMax) [note: parentheses unnecessary] Scala: if (vMin <= vNum && vNum <= vMax) Swift: if (vMin <= vNum && vNum <= vMax) UFL: Mod [or TruncMod][C-style modulo (output sign based on 1st param)][e.g. most languages use %] AutoHotkey: Mod C++: fmod [can use: %] C#: ___ [can use: %] Crystal: remainder [e.g. vNum1.remainder(vNum2)] Excel: ___ [WARNING: Excel's MOD is a floor mod, Excel VBA's Mod operator is a C-style mod] Excel VBA: ___ [can use: Mod operator e.g. a Mod b] [WARNING: unlike the Excel sheet function MOD, Mod in VBA rounds floats to integers] Go: math.Mod [can use: %] [also: math.Remainder] [note: % works on ints only] Java: ___ [can use: %] JavaScript: ___ [can use: %] Kotlin: ___ [can use: %] PHP: fmod [can use: %] Python: math.fmod [can use: divmod (returns quotient and remainder as a tuple)] R: ___ Ruby: remainder [e.g. vNum1.remainder(vNum2)] Rust: ___ [can use: %, checked_rem] [note: rem_euclid always returns positive/zero] Scala: ___ [can use: %] Swift: fmod [can use: %] UFL: FloorMod [floor modulo (output sign based on 2nd param][e.g. R uses %%][WARNING: Python uses %] AutoHotkey: ___ C++: ___ C#: ___ Crystal: modulo [e.g. vNum1.modulo(vNum2)] [also: %] [WARNING (% and modulo): floor mod, not C-style mod] Excel: MOD [WARNING: Excel's MOD is a floor mod, Excel VBA's Mod operator is a C-style mod] Excel VBA: ___ Go: ___ Java: Math.floorMod JavaScript: ___ Kotlin: ___ PHP: ___ Python: operator.mod [also: %] [WARNING (% and mod): floor mod, not C-style mod] R: ___ [can use: vNum1 %% vNum2] Ruby: modulo [e.g. vNum1.modulo(vNum2)] [also: %] [WARNING (% and modulo): floor mod, not C-style mod] Rust: ___ Scala: math.floorMod Swift: ___ UFL: (ModPsvDemo) [do 'a mod b', where a is positive/0/negative, where b is *positive*, and where the output is always positive (or zero)] AutoHotkey: Mod(Mod(vNum1,vNum2)+vNum2,vNum2) C++: (vNum1 % vNum2 + vNum2) % vNum2 C#: (vNum1 % vNum2 + vNum2) % vNum2 Crystal: vNum1 % vNum2 Excel: MOD(A1,B1) Excel VBA: (vNum1 Mod vNum2 + vNum2) Mod vNum2 [WARNING: Excel VBA's Mod operator only handles integers] Go: (vNum1 % vNum2 + vNum2) % vNum2 Java: Math.floorMod(vNum1, vNum2) JavaScript: (vNum1 % vNum2 + vNum2) % vNum2 Kotlin: (vNum1 % vNum2 + vNum2) % vNum2 PHP: ($vNum1 % $vNum2 + $vNum2) % $vNum2 Python: vNum1 % vNum2 R: vNum1 %% vNum2 Ruby: vNum1 % vNum2 Rust: (vNum1 % vNum2 + vNum2) % vNum2 Scala: math.floorMod(vNum1, vNum2) Swift: (vNum1 % vNum2 + vNum2) % vNum2 UFL: TrueDiv [or Div/FloatDiv][standard division, takes two numbers and returns a float][for languages where / on ints doesn't do true division, you can cast one or both numbers to a float first][see also: IntToFloat] AutoHotkey: ___ [can use: vNum1/vNum2] C++: ___ [can use: vNum1/(double)vNum2] [WARNING: / on ints uses C-style integer division] C#: ___ [can use: vNum1/(double)vNum2] [WARNING: / on ints uses C-style integer division] Crystal: ___ [can use: vNum1/vNum2] Excel: ___ [can use: vNum1/vNum2] Excel VBA: ___ [can use: vNum1/vNum2] Go: ___ [can use: float64(vNum1) / float64(vNum2)] Java: ___ [can use: vNum1/(double)vNum2] [WARNING: / on ints uses C-style integer division] JavaScript: ___ [can use: vNum1/vNum2] Kotlin: ___ [can use: vNum1/vNum2.toDouble()] [WARNING: / on ints uses C-style integer division] PHP: fdiv [e.g. fdiv($vNum1, $vNum2)] [also: $vNum1/$vNum2] Python: operator.truediv [e.g. operator.truediv(vNum1, vNum2)] [also (Python 3 onwards): vNum1/vNum2] [note: Python 1 and 2: / on ints uses floor division] R: ___ [can use: vNum1/vNum2] Ruby: ___ [can use: vNum1/vNum2.to_f] [WARNING: / on ints uses floor division] Rust: ___ [can use: vNum1 as f64/vNum2 as f64] [WARNING: / on ints uses C-style integer division] Scala: ___ [can use: vNum1/vNum2.toDouble] [WARNING: / on ints uses C-style integer division] Swift: ___ [can use: vNum1/Double(vNum2)] [WARNING: / on ints uses C-style integer division] UFL: IntDiv [or TruncDiv][divide then round towards zero (remove the fractional part)][e.g. Dart uses ~/][see also: FloatToInt/Trunc/IntToFloat] AutoHotkey: ___ [can use: Integer(vNum1/vNum2)] [also (AHK v2, ints only): vNum1//vNum2] [WARNING: // is floor division in Python, trunc division in AHK v2] C++: ___ [can use: trunc(vNum1/(double)vNum2)] [also (ints only): vNum1/vNum2] C#: ___ [can use: Math.Truncate(vNum1/(double)vNum2)] [also (ints only): vNum1/vNum2] Crystal: ___ [can use: (vNum1/vNum2).to_i] Excel: QUOTIENT [e.g. QUOTIENT(A1,vNum)] Excel VBA: WorksheetFunction.Quotient [e.g. WorksheetFunction.Quotient(vNum1, vNum2)] [also: vNum1 \ vNum2] [WARNING: backslash operator ('\') easily confused with slash operator ('/')] Go: ___ [can use: math.Trunc(vNum1/vNum2)] [also (ints only): vNum1/vNum2] Java: ___ [can use: vNum = (int)(vNum1/vNum2)] [also: Double.valueOf(vNum1/vNum2).intValue()] [also (ints only): vNum1/vNum2] JavaScript: ___ [can use: Math.trunc(vNum1/vNum2)] Kotlin: ___ [can use: (vNum1/vNum2).toInt()] [also: kotlin.math.truncate(vNum1/vNum2.toDouble())] [also (ints only): vNum1/vNum2] PHP: intdiv [e.g. intdiv($vNum1, $vNum2)] [also: (int)($vNum1/$vNum2)] Python: ___ [can use (Python 3 onwards): int(vNum1/vNum2)] [can use (works on Python 2 and 3): int(vNum1/float(vNum2))] R: ___ [can use: trunc(vNum1/vNum2)] Ruby: ___ [can use: (vNum1/vNum2.to_f).to_i] [note: ensure at least one value is a float, so true division occurs, then cast to int] Rust: ___ [can use: (vNum1 as f64/vNum2 as f64).trunc()] [also (ints only): vNum1/vNum2] Scala: ___ [can use: vNum = (vNum1/vNum2).toInt] [also (ints only): vNum1/vNum2] Swift: ___ [can use: trunc(vNum1/vNum2)] [also (ints only): vNum1/vNum2] [requires (trunc): import Foundation] UFL: FloorDiv [divide then round down (towards -infinity)][e.g. Python uses //][see also: Floor/IntToFloat] AutoHotkey: ___ [can use: Floor(vNum1/vNum2)] [WARNING: in AHK v1, but not AHK v2: // did trunc division if both values were ints, else floor division] C++: ___ [can use: floor(vNum1/(double)vNum2)] C#: ___ [can use: Math.Floor(vNum1/(double)vNum2)] Crystal: ___ [can use: vNum1//vNum2] [also: (vNum1/vNum2).floor] [also: divmod (returns quotient and remainder as an array), e.g. vNum1.divmod(vNum2)[0]] [note: fails: vInt.divmod(vFloat)] Excel: ___ [can use: INT(A1/vNum)] [WARNING: Excel's INT function works like a floor function] Excel VBA: ___ [can use: Int(vNum1/vNum2)] [WARNING: Excel VBA's Int function works like a floor function] Go: ___ [can use: math.Floor(float64(vNum1) / float64(vNum2))] Java: Math.floorDiv [e.g. (ints only): Math.floorDiv(vNum1, vNum2)] [also: Math.floor(vNum1/(double)vNum2)] JavaScript: ___ [can use: Math.floor(vNum1/vNum2)] Kotlin: Math.floorDiv [e.g. (ints only): Math.floorDiv(vNum1, vNum2)] [also: Math.floor(vNum1/vNum2.toDouble())] PHP: ___ [can use: floor($vNum1/$vNum2)] Python: operator.floordiv [e.g. operator.floordiv(vNum1, vNum2)] [also: vNum1//vNum2] [also: divmod (returns quotient and remainder as a tuple), e.g. divmod(vNum1, vNum2)[0]] R: ___ [can use: vNum1 %/% vNum2] [also: floor(vNum1/vNum2)] Ruby: ___ [can use: (vNum1/vNum2).floor] [also: divmod (returns quotient and remainder as an array), e.g. vNum1.divmod(vNum2)[0]] [also (ints only): vNum1/vNum2] Rust: ___ [can use: (vNum1 as f64/vNum2 as f64).floor()] Scala: math.floorDiv [e.g. (ints only): math.floorDiv(vNum1, vNum2)] [also: math.floor(vNum1/vNum2.toDouble)] Swift: ___ [can use: floor(vNum1/Double(vNum2))] UFL: (Hypot) [for a right-angled triangle, given the lengths of the 2 orthogonal sides, calculate the length of the hypotenuse][some implementations accept any number of values, not just 2] AutoHotkey: ___ C++: hypot C#: Math.Hypot Crystal: Math.hypot Excel: ___ Excel VBA: ___ Go: math.Hypot Java: Math.hypot JavaScript: Math.hypot Kotlin: Math.hypot PHP: hypot Python: math.hypot R: ___ Ruby: Math.hypot Rust: hypot Scala: math.hypot Swift: hypot UFL: (Fact) [factorial][see also: Gamma] AutoHotkey: ___ C++: ___ C#: ___ Crystal: ___ Excel: FACT Excel VBA: WorksheetFunction.Fact Go: ___ Java: ___ JavaScript: ___ Kotlin: ___ PHP: ___ Python: math.factorial R: factorial Ruby: ___ Rust: ___ Scala: ___ Swift: ___ UFL: (IsPrime) [is prime] AutoHotkey: ___ C++: ___ C#: ___ Crystal: ___ Excel: ___ Excel VBA: ___ Go: ___ Java: ___ JavaScript: ___ Kotlin: ___ PHP: ___ Python: ___ R: ___ Ruby: prime [e.g. vIsPrime = Prime.prime?(vNum)] [requires: require "prime"] Rust: ___ Scala: ___ Swift: ___ UFL: (Triang) [triangular number][see also: Range.ToArray, Array.Sum, Sum] AutoHotkey: ___ C++: ___ C#: ___ Crystal: ___ Excel: ___ Excel VBA: ___ Go: ___ Java: ___ JavaScript: ___ Kotlin: ___ PHP: ___ Python: ___ R: ___ Ruby: ___ Rust: ___ Scala: ___ Swift: ___ UFL: (Fib) [Fibonacci number] AutoHotkey: ___ C++: ___ C#: ___ Crystal: ___ Excel: ___ Excel VBA: ___ Go: ___ Java: ___ JavaScript: ___ Kotlin: ___ PHP: ___ Python: ___ R: ___ Ruby: ___ Rust: ___ Scala: ___ Swift: ___ UFL: (DegToRad)/(RadToDeg) [degrees to radians/radians to degrees] AutoHotkey: ___/___ C++: ___/___ C#: ___/___ Crystal: ___/___ Excel: RADIANS/DEGREES Excel VBA: WorksheetFunction.Radians/WorksheetFunction.Degrees Go: ___/___ Java: Math.toRadians/Math.toDegrees JavaScript: ___/___ Kotlin: Math.toRadians/Math.toDegrees PHP: deg2rad/rad2deg Python: math.radians/math.degrees R: ___/___ Ruby: ___/___ Rust: to_radians/to_degrees Scala: math.toRadians/math.toDegrees Swift: ___/___ UFL: Sin/Cos/Tan [e.g. in right-angled triangles, given an angle, calculate the relative dimensions of 2 sides][e.g. tan(x)=opp/adj][e.g. opp/adj = tan(1.107149 rad) = tan(63.434949 deg) = 2][so for angle 63.434949 deg, the opposite side is twice as long as the adjacent side] AutoHotkey: Sin/Cos/Tan C++: sin/cos/tan C#: Math.Sin/Math.Cos/Math.Tan Crystal: Math.sin/Math.cos/Math.tan Excel: SIN/COS/TAN Excel VBA: Sin/Cos/Tan Go: math.Sin/math.Cos/math.Tan Java: Math.sin/Math.cos/Math.tan JavaScript: Math.sin/Math.cos/Math.tan Kotlin: Math.sin/Math.cos/Math.tan PHP: sin/cos/tan Python: math.sin/math.cos/math.tan R: sin/cos/tan Ruby: Math.sin/Math.cos/Math.tan Rust: sin/cos/tan Scala: math.sin/math.cos/math.tan Swift: sin/cos/tan UFL: ASin/ACos/ATan [e.g. in right-angled triangles, given 2 side lengths calculate an angle size][e.g. tan(x)=opp/adj, so x = atan(opp/adj)][e.g. x = atan(2) = 1.107149 rad = 63.434949 deg][so when the opposite side is twice as long as the adjacent side, the angle is 63.434949 deg] AutoHotkey: ASin/ACos/ATan C++: asin/acos/atan C#: Math.Asin/Math.Acos/Math.Atan Crystal: Math.asin/Math.acos/Math.atan Excel: ASIN/ACOS/ATAN Excel VBA: WorksheetFunction.Asin/WorksheetFunction.Acos/Atn [note: 'Atn', not 'Atan'] Go: math.Asin/math.Acos/math.Atan Java: Math.asin/Math.acos/Math.atan JavaScript: Math.asin/Math.acos/Math.atan Kotlin: Math.asin/Math.acos/Math.atan PHP: asin/acos/atan Python: math.asin/math.acos/math.atan R: asin/acos/atan Ruby: Math.asin/Math.acos/Math.atan Rust: asin/acos/atan Scala: math.asin/math.acos/math.atan Swift: asin/acos/atan UFL: ATan2 [a 4-quadrant version of atan][note: the (y,x) parameter order matches the common calculation: atan(y/x)][note: atan2(y=0,x=-0.0) = pi] AutoHotkey: ATan2 [note: parameters: y, x] C++: atan2 [note: parameters: y, x] C#: Math.Atan2 [note: parameters: y, x] Crystal: Math.atan2 [note: parameters: y, x] Excel: ATAN2 [WARNING: parameters: x, y (uncommon param order)] Excel VBA: WorksheetFunction.Atan2 [WARNING: parameters: x, y (uncommon param order)] Go: math.Atan2 [note: parameters: y, x] Java: Math.atan2 [note: parameters: y, x] JavaScript: Math.atan2 [note: parameters: y, x] [e.g. Math.atan2(vNumY, vNumX)] Kotlin: Math.atan2 [note: parameters: y, x] PHP: atan2 [note: parameters: y, x] Python: math.atan2 [note: parameters: y, x] R: atan2 [note: parameters: y, x] Ruby: Math.atan2 [note: parameters: y, x] Rust: atan2 [note: parameters: y, x] [e.g. vNumY.atan2(vNumX)] Scala: math.atan2 [note: parameters: y, x] Swift: atan2 [note: parameters: y, x] [WARNING: there may be some extant or deprecated functions that use the x, y order] [requires: import Foundation] UFL: (SinDeg)/(CosDeg)/(TanDeg)/(ASinDeg)/(ACosDeg)/(ATanDeg)/(ATan2Deg) [degree-versions of trigonometric functions][e.g. TanDeg takes degrees, e.g. ATanDeg returns degrees] AutoHotkey: ___/___/___/___/___/___/___ C++: ___/___/___/___/___/___/___ C#: ___/___/___/___/___/___/___ Crystal: ___/___/___/___/___/___/___ Excel: ___/___/___/___/___/___/___ Excel VBA: ___/___/___/___/___/___/___ Go: ___/___/___/___/___/___/___ Java: ___/___/___/___/___/___/___ JavaScript: ___/___/___/___/___/___/___ Kotlin: ___/___/___/___/___/___/___ PHP: ___/___/___/___/___/___/___ Python: ___/___/___/___/___/___/___ R: ___/___/___/___/___/___/___ Ruby: ___/___/___/___/___/___/___ Rust: ___/___/___/___/___/___/___ Scala: ___/___/___/___/___/___/___ Swift: ___/___/___/___/___/___/___ UFL: DecToBase [integer to string][convert integer to string (in base n)][base convert] AutoHotkey: ___ C++: itoa [e.g. itoa(vNum, oBuffer, vBase)] [also: _ui64tow] [WARNING: itoa isn't built-in (in the std library)] C#: Convert.ToString [e.g. Convert.ToString(vNum, vBase)] [WARNING: Convert.ToString/Convert.ToInt32 only handle bases 2/8/10/16] Crystal: to_s [e.g. vNum.to_s(vBase)] Excel: BASE [e.g. BASE(vNum,vBase)] [note: added in Excel 2013] Excel VBA: WorksheetFunction.Base [e.g. WorksheetFunction(vNum, vBase)] [also (for dec2hex): Hex] Go: strconv.FormatInt [e.g. strconv.FormatInt(int64(vNum), vBase)] [also: strconv.FormatUint(uint64(vNum), vBase)] Java: Integer.toString [e.g. Integer.toString(vNum, vBase)] [also: String.format] JavaScript: toString [e.g. parseInt(vNum, vBase)] Kotlin: Integer.toString [e.g. Integer.toString(vNum, vBase)] [also: vNum.toString(vBase)] PHP: base_convert [e.g. base_convert($vNum, 10, $vBase)] Python: ___ [can use: bin/oct/hex] [WARNING: bin/oct/hex all add a 2-char prefix ('0b'/'0o'/'0x')] R: ___ [can use: as.octmode/as.hexmode] [can use (oct/hex): sprintf] Ruby: to_s [e.g. vNum.to_s(vBase)] Rust: ___ [can use: format, WARNING: only handles bases 2/8/10/16] [e.g. base 16: format!("{:x}", vNum)] [e.g. base 2: format!("{:b}", vNum)] [e.g. base 8: format!("{:o}", vNum)] Scala: Integer.toString [e.g. Integer.toString(vNum, vBase)] [also: String.format] Swift: String [e.g. String(vNum, radix:vBase)] UFL: BaseToDec [string to integer][convert string (in base n) to integer][base convert] AutoHotkey: ___ C++: std::stoi [e.g. std::stoi(vText, NULL, vBase)] [also: _wcstoi64/atoi/strtol] C#: Convert.ToInt32 [e.g. Convert.ToInt32(vText, vBase)] [WARNING: Convert.ToString/Convert.ToInt32 only handle bases 2/8/10/16] Crystal: to_i [e.g. vText.to_i(vBase)] Excel: DECIMAL [e.g. DECIMAL(vText,vBase)] [note: added in Excel 2013] Excel VBA: WorksheetFunction.Decimal [e.g. WorksheetFunction.Decimal(vText, vBase)] [also (for hex2dec): CLngLng/CDbl/CDec with '&H' (not '0x') prefix (probably avoid CLng/CInt/Val/Abs, e.g. test with '&HF'/'&HFFFFFFFF'/'&HFFFFFFFF')] Go: strconv.ParseInt [e.g. strconv.ParseInt(vText, vBase, 64)] [also: strconv.ParseUint(vText, vBase, 64)] [note: 64 to create an int64/uint64] Java: Integer.parseInt [e.g. Integer.parseInt(vText, vBase)] JavaScript: parseInt [e.g. vText.toString(vBase)] Kotlin: Integer.parseInt [e.g. Integer.parseInt(vText, vBase)] PHP: base_convert [e.g. base_convert($vText, $vBase, 10)] Python: int [e.g. int(vText, vBase)] R: strtoi [e.g. strtoi(vText, vBase)] Ruby: to_i [e.g. vText.to_i(vBase)] Rust: from_str_radix [e.g. i32::from_str_radix(vText, vBase).unwrap()] Scala: Integer.parseInt [e.g. Integer.parseInt(vText, vBase)] Swift: strtol [also: strtoul/strtoll/strtoull] [e.g. strtol(vText, nil, vBase)] UFL: (DecToBin) [convert integer to string (in base 2)] AutoHotkey: ___ C++: ___ [can use: itoa] C#: ___ [can use: Convert.ToString] Crystal: to_s [e.g. vNum.to_s(2)] Excel: DEC2BIN Excel VBA: WorksheetFunction.Dec2Bin Go: strconv.FormatInt [e.g. strconv.FormatInt(int64(vNum), 2)] [also: strconv.FormatUint(uint64(vNum), 2)] Java: Integer.toBinaryString JavaScript: ___ [can use: toString] Kotlin: Integer.toBinaryString PHP: decbin Python: bin [WARNING: adds a 2-char prefix ('0b')] R: ___ [can use: paste(as.integer(rev(intToBits(vNum))), collapse="")] [note (to remove leading zeros): sub("^0+(?=.)", "", vText, perl=TRUE)] Ruby: to_s [e.g. vNum.to_s(2)] Rust: ___ [can use: format] Scala: Integer.toBinaryString Swift: ___ [can use: String] UFL: (BinToDec) [convert string (in base 2) to integer] AutoHotkey: ___ C++: ___ [can use: atoi] C#: ___ [can use: Convert.ToInt32] Crystal: to_i [e.g. vText.to_i(2)] Excel: BIN2DEC Excel VBA: WorksheetFunction.Bin2Dec Go: strconv.ParseInt [e.g. strconv.ParseInt(vText, 2, 64)] [also: strconv.ParseUint(vText, 2, 64)] Java: ___ [can use: Integer.parseInt] JavaScript: ___ [can use: parseInt] Kotlin: ___ [can use: Integer.parseInt] PHP: bindec Python: ___ [can use: int] R: strtoi [e.g. strtoi(vText, 2)] Ruby: to_i [e.g. vText.to_i(2)] Rust: ___ [can use: from_str_radix] Scala: ___ [can use: Integer.parseInt] Swift: ___ [can use: strtol] UFL: (DecToOct) [convert integer to string (in base 8)] AutoHotkey: ___ C++: ___ [can use: itoa] C#: ___ [can use: Convert.ToString] Crystal: to_s [e.g. vNum.to_s(8)] Excel: DEC2OCT Excel VBA: WorksheetFunction.Dec2Oct [also: Oct] Go: strconv.FormatInt [e.g. strconv.FormatInt(int64(vNum), 8)] [also: strconv.FormatUint(uint64(vNum), 8)] Java: Integer.toOctalString JavaScript: ___ [can use: toString] Kotlin: Integer.toOctalString PHP: decoct Python: oct [WARNING: adds a 2-char prefix ('0o')] R: ___ as.octmode [e.g. as.character(as.octmode(vNum))] [also: sprintf("%o", vNum)] Ruby: to_s [e.g. vNum.to_s(8)] Rust: ___ [can use: format] Scala: Integer.toOctalString Swift: ___ [can use: String] UFL: (OctToDec) [convert string (in base 8) to integer] AutoHotkey: ___ C++: ___ [can use: atoi] C#: ___ [can use: Convert.ToInt32] Crystal: to_i [e.g. vText.to_i(8)] Excel: OCT2DEC Excel VBA: WorksheetFunction.Oct2Dec [also: CLngLng/CDbl/CDec with '&O' (not '0o') prefix (based on tests with Hex(): probably avoid CLng/CInt/Val/Abs)] Go: strconv.ParseInt [e.g. strconv.ParseInt(vText, 8, 64)] [also: strconv.ParseUint(vText, 8, 64)] Java: ___ [can use: Integer.parseInt] JavaScript: ___ [can use: parseInt] Kotlin: ___ [can use: Integer.parseInt] PHP: octdec Python: ___ [can use: int] R: strtoi [e.g. strtoi(vText, 8)] Ruby: to_i [e.g. vText.to_i(8)] Rust: ___ [can use: from_str_radix] Scala: ___ [can use: Integer.parseInt] Swift: ___ [can use: strtol] UFL: (DecToHex) [convert integer to string (in base 16)] AutoHotkey: ___ C++: ___ [can use: itoa] C#: ___ [can use: Convert.ToString] Crystal: to_s [e.g. vNum.to_s(16)] Excel: DEC2HEX Excel VBA: WorksheetFunction.Dec2Hex [also: Hex] Go: strconv.FormatInt [e.g. strconv.FormatInt(int64(vNum), 16)] [also: strconv.FormatUint(uint64(vNum), 16)] Java: Integer.toHexString JavaScript: ___ [can use: toString] Kotlin: Integer.toHexString PHP: dechex Python: hex [WARNING: adds a 2-char prefix ('0x')] R: ___ as.hexmode [e.g. as.character(as.hexmode(vNum))] [also: sprintf("%x", vNum)] Ruby: to_s [e.g. vNum.to_s(16)] Rust: ___ [can use: format] Scala: Integer.toHexString Swift: ___ [can use: String] UFL: (HexToDec) [convert string (in base 16) to integer] AutoHotkey: ___ C++: ___ [can use: atoi] C#: ___ [can use: Convert.ToInt32] Crystal: to_i [e.g. vText.to_i(16)] Excel: HEX2DEC Excel VBA: WorksheetFunction.Hex2Dec [also: CLngLng/CDbl/CDec with '&H' (not '0x') prefix (probably avoid CLng/CInt/Val/Abs, e.g. test with '&HF'/'&HFFFFFFFF'/'&HFFFFFFFF')] Go: strconv.ParseInt [e.g. strconv.ParseInt(vText, 16, 64)] [also: strconv.ParseUint(vText, 16, 64)] Java: ___ [can use: Integer.parseInt] JavaScript: ___ [can use: parseInt] Kotlin: ___ [can use: Integer.parseInt] PHP: hexdec Python: ___ [can use: int] R: strtoi [e.g. strtoi(vText, 16)] Ruby: to_i [e.g. vText.to_i(16)] Rust: ___ [can use: from_str_radix] Scala: ___ [can use: Integer.parseInt] Swift: ___ [can use: strtol] UFL: Combin/CombinR [get count of: combinations without repetition, combinations with repetition] AutoHotkey: ___/___ C++: ___/___ C#: ___/___ Crystal: ___/___ Excel: COMBIN/COMBINA Excel VBA: WorksheetFunction.Combin/___ Go: ___/___ Java: ___/___ JavaScript: ___/___ Kotlin: ___/___ PHP: ___/___ Python: math.comb/___ R: choose/___ Ruby: ___/___ Rust: ___/___ Scala: ___/___ Swift: ___/___ UFL: Permut/PermutR [get count of: permutations without repetition, permutations with repetition] AutoHotkey: ___/___ C++: ___/___ C#: ___/___ Crystal: ___/___ Excel: PERMUT/PERMUTATIONA Excel VBA: WorksheetFunction.Permut/___ Go: ___/___ Java: ___/___ JavaScript: ___/___ Kotlin: ___/___ PHP: ___/___ Python: math.perm/___ R: ___/___ Ruby: ___/___ Rust: ___/___ Scala: ___/___ Swift: ___/___ UFL: GCD [or HCF][greatest common divisor (highest common factor)][could potentially handle n params/an array] AutoHotkey: ___ C++: std::gcd C#: BigInteger.GreatestCommonDivisor Crystal: gcd [e.g. vNum1.gcd(vNum2)] Excel: GCD Excel VBA: WorksheetFunction.Gcd Go: ___ Java: ___ JavaScript: ___ Kotlin: ___ PHP: ___ Python: math.gcd R: ___ Ruby: gcd [e.g. vNum1.gcd(vNum2)] Rust: ___ Scala: ___ Swift: ___ UFL: LCM [lowest common multiple][could potentially handle n params/an array] AutoHotkey: ___ C++: std::lcm C#: ___ Crystal: lcm [e.g. vNum1.lcm(vNum2)] Excel: LCM Excel VBA: WorksheetFunction.Lcm Go: ___ Java: ___ JavaScript: ___ Kotlin: ___ PHP: ___ Python: math.lcm R: ___ Ruby: lcm [e.g. vNum1.lcm(vNum2)] Rust: ___ Scala: ___ Swift: ___ UFL: (NumCompare) [note: can typically also use: < > ==][compares numbers and returns 1/0/-1 accordingly (or positive/0/negative)][see also: Sign/StrCompare] AutoHotkey: ___ C++: ___ [can use: <=>] [e.g. int vCmp = (int)std::bit_cast<int8_t>(vNum1 <=> vNum2)] C#: CompareTo [e.g. vCmp = vNum1.CompareTo(vNum2)] Crystal: ___ [can use: <=>] [e.g. vCmp = vNum1 <=> vNum2] Excel: ___ [can use: SIGN(vNum1-vNum2)] Excel VBA: ___ [can use: vCmp = Sgn(vNum1-vNum2)] Go: ___ Java: Integer.compare [e.g. vCmp = Integer.compare(vNum1, vNum2)] [also: Double.compare] JavaScript: ___ [can use: vCmp = Math.sign(vNum1-vNum2)] Kotlin: compareValues [e.g. vCmp = compareValues(vNum1, vNum2)] [also: compareValuesBy] PHP: ___ [can use: <=>] [e.g. $vCmp = $vNum1 <=> $vNum2] Python: ___ R: ___ [can use: vCmp = sign(vNum1-vNum2)] Ruby: ___ [can use: <=>] [e.g. vCmp = vNum1 <=> vNum2] Rust: cmp [e.g. vCmp = vNum1.cmp(&vNum2) as i32] [also (partial_cmp): e.g. vCmp = vFloat1.partial_cmp(&vFloat2).unwrap() as i32] [note: floats implement the PartialOrd trait but not the Ord trait] Scala: compare [e.g. vCmp = vNum1.compare(vNum2)] [also: vCmp = Integer.compare(vNum1, vNum2)] [also (not available by default): Double.compare] Swift: ___ UFL: VerCompare [or IPCompare][e.g. compare '1.2.3.4' against '1.2', and/or handle SemVer][e.g. compare IP addresses (IPv4 and/or IPv6)] AutoHotkey: VerCompare C++: ___ C#: ___ Crystal: ___ Excel: ___ Excel VBA: ___ Go: ___ Java: ___ JavaScript: ___ Kotlin: ___ PHP: version_compare Python: ___ R: compareVersion [WARNING: compareVersion("1.0", "1") returns 1 (not 0)] Ruby: ___ [can use: <=>] [e.g. vCmp = Gem::Version.new(vVersion1) <=> Gem::Version.new(vVersion2)] Rust: ___ Scala: ___ Swift: ___ UFL: PopCount32/PopCount64 [or PopCnt][population count, count the 1 bits in the integer's binary representation] AutoHotkey: ___/___ C++: std::popcount/std::popcount [e.g. std::popcount((std::uint64_t)vNum)] C#: BitOperations.PopCount/BitOperations.PopCount Crystal: ___ [can use: vNum.to_s(2).count("1")] Excel: ___/___ Excel VBA: ___/___ Go: bits.OnesCount32/bits.OnesCount64 [e.g. bits.OnesCount32(uint32(vNum))] [e.g. bits.OnesCount64(uint64(vNum))] [requires: import "math/bits"] Java: Integer.bitCount/Long.bitCount JavaScript: ___/___ Kotlin: Integer.bitCount/java.lang.Long.bitCount PHP: ___/___ [note: PHP has gmp_popcount] Python: int.bit_count/int.bit_count [e.g. vNum.bit_count()] R: ___/___ [can use: sum(intToBits(vNum)>0)] [note: intToBits() handles 32-bit signed ints (-0x80000000 to 0x7FFFFFFF)] [WARNING: as.integer() and intToBits() store -0x80000000 as NA] Ruby: ___ [can use: vNum.to_s(2).count("1")] Rust: count_ones/count_ones Scala: Integer.bitCount/Long.bitCount Swift: ___/___ UFL: (BitAnd)/(BitOr)/(BitXor) [And/Or/Xor could potentially handle n params/an array] AutoHotkey: ___/___/___ [can use: & | ^] C++: ___/___/___ [can use: & | ^] C#: ___/___/___ [can use: & | ^] Crystal: ___/___/___ [can use: & | ^] Excel: BITAND/BITOR/BITXOR [note: added in Excel 2013] Excel VBA: WorksheetFunction.Bitand/WorksheetFunction.Bitor/WorksheetFunction.Bitxor [can use (operators): And Or Xor] Go: ___/___/___ [can use: & | ^] Java: ___/___/___ [can use: & | ^] JavaScript: ___/___/___ [can use: & | ^] Kotlin: ___/___/___ [can use (operators): and or xor] PHP: ___/___/___ [can use: & | ^] [also: gmp_and/gmp_or/gmp_xor, variant_and] Python: operator.and_/operator.or_/operator.xor [can use: & | ^] R: bitwAnd/bitwOr/bitwXor [e.g. bitwAnd(vNum1, vNum2)] [also (hexmode/octmode): & | xor] Ruby: ___/___/___ [can use: & | ^] Rust: ___/___/___ [can use: & | ^] Scala: ___/___/___ [can use: & | ^] Swift: ___/___/___ [can use: & | ^] UFL: (BitNot) [note: 'xor' then 'or' can be used to do 'not' to a specified number of bits] AutoHotkey: ___ [can use: ~] C++: ___ [can use: ~] C#: ___ [can use: ~] Crystal: ___ [can use: ~] Excel: ___ Excel VBA: ___ [can use (operator): Not] [WARNING: Excel VBA's Not is logical not (for bools) and bitwise not (for ints)] Go: ___ [can use: ^] [note: ^vNum is bitwise-not (unary operator), vNum1 ^ vNum2 is bitwise-xor (binary operator)] [WARNING: unusual symbol for bitwise-not operator] Java: ___ [can use: ~] JavaScript: ___ [can use: ~] Kotlin: inv [e.g. vNum.inv()] PHP: ___ [can use: ~] [also: variant_not] Python: operator.invert [also: operator.inv] [can use: ~] R: bitwNot [e.g. bitwNot(vNum)] Ruby: ___ [can use: ~] Rust: ___ [can use: !] [WARNING: Rust's ! is logical not (for bools) and bitwise not (for ints)] Scala: ___ [can use: ~] Swift: ___ [can use: ~] UFL: (BitShiftLeft) [treating an int as a sequence of bits, move bits left, discard overflow, and zero-fill the right end] AutoHotkey: ___ [can use: <<] C++: ___ [can use: <<] C#: ___ [can use: <<] Crystal: ___ [can use: <<] Excel: BITLSHIFT [note: added in Excel 2013] [can use (operators): And Or * / ^ (note: And and Or are bitwise for integer operands)] Excel VBA: WorksheetFunction.Bitlshift [note: added in Excel 2013] Go: ___ [can use: <<] Java: ___ [can use: <<] JavaScript: ___ [can use: <<] Kotlin: ___ [can use (operator): shl] PHP: ___ [can use: <<] Python: operator.lshift [can use: <<] R: bitwShiftL Ruby: ___ [can use: <<] Rust: ___ [can use: <<] Scala: ___ [can use: <<] Swift: ___ [can use: <<] UFL: (BitShiftRight)/(BitShiftRightLogical) [treating an int as a sequence of bits, move bits rights, discard overflow, and zero-fill/one-fill the left (one-fill if first bit is 1 and shift is non-logical, else zero-fill)] AutoHotkey: ___/___ [can use: >> >>>] C++: ___/___ [can use: >> (>> is signed/unsigned based on the type)] C#: ___/___ [can use: >> >>>] Crystal: ___/___ [can use: >>] Excel: BITRSHIFT/___ [note: added in Excel 2013] [can use (operators): And Or * / ^ (note: And and Or are bitwise for integer operands)] Excel VBA: WorksheetFunction.Bitrshift/___ [note: added in Excel 2013] Go: ___/___ [can use: >>] Java: ___/___ [can use: >> >>>] JavaScript: ___/___ [can use: >> >>>] Kotlin: ___/___ [can use (operators): shr/ushr] [note: ushr throws when used with *unsigned* integers] PHP: ___/___ [can use: >>] Python: operator.rshift/___ [can use: >>] R: ___/bitwShiftR [appears to return unsigned, unless shift is 0, which maintains sign] Ruby: ___/___ [can use: >>] Rust: ___/___ [can use: >>] Scala: ___/___ [can use: >> >>>] Swift: ___/___ [can use: >>] UFL: (BitRotateLeft)/(BitRotateRight) [bit-rotate left: treating an int as a sequence of bits, move bits left, place overflow at the right end][bit-rotate right: move right, place overflow at left end] AutoHotkey: ___/___ C++: ___/___ C#: BitOperations.RotateLeft/BitOperations.RotateRight Crystal: rotate_left/rotate_right Excel: ___/___ Excel VBA: ___/___ Go: bits.RotateLeft64/___ [e.g. bits.RotateLeft64(uint64(vNum), vCount)] [note: can rotate right by passing a negative count to bits.RotateLeft64()] [requires: import "math/bits"] Java: Integer.rotateLeft/Integer.rotateRight JavaScript: ___/___ Kotlin: Integer.rotateLeft/Integer.rotateRight PHP: ___/___ Python: ___/___ R: ___/___ Ruby: ___/___ Rust: rotate_left/rotate_right Scala: Integer.rotateLeft/Integer.rotateRight Swift: ___/___ UFL: MRound [round to the nearest multiple of n][see also: RoundDP] AutoHotkey: ___ C++: ___ C#: ___ Crystal: ___ Excel: MROUND Excel VBA: WorksheetFunction.MRound Go: ___ Java: ___ JavaScript: ___ Kotlin: ___ PHP: ___ Python: ___ R: ___ Ruby: ___ Rust: ___ Scala: ___ Swift: ___ UFL: (Nearest) [return the nearest number: Nearest(vNum, oNums*)][e.g. use case: round to the nearest multiple of 5 (an alternative to MRound): Nearest(vNum, vNum-vNum%5, vNum-vNum%5+5)] AutoHotkey: ___ C++: ___ C#: ___ Crystal: ___ Excel: ___ Excel VBA: ___ Go: ___ Java: ___ JavaScript: ___ Kotlin: ___ PHP: ___ Python: ___ R: ___ Ruby: ___ Rust: ___ Scala: ___ Swift: ___ UFL: (NumToRom)/(RomToNum) [Arabic numerals to Roman numerals, and vice versa] AutoHotkey: ___/___ C++: ___/___ C#: ___/___ Crystal: ___/___ Excel: ROMAN/ARABIC [note: ARABIC added in Excel 2013] Excel VBA: WorksheetFunction.Roman/WorksheetFunction.Arabic Go: ___/___ Java: ___/___ JavaScript: ___/___ Kotlin: ___/___ PHP: ___/___ Python: ___/___ R: as.roman/as.numeric [e.g. vRom = as.roman(vNum)][e.g. vNum = as.numeric(vRom)] Ruby: ___/___ Rust: ___/___ Scala: ___/___ Swift: ___/___ UFL: Gamma [gamma function][note: gamma(n) is the same as fact(n-1) for integers n > 0, e.g. Gamma(5)=Fact(4)=24][see also: Fact] AutoHotkey: ___ C++: tgamma C#: ___ Crystal: Math.gamma Excel: GAMMA [note: added in Excel 2013] Excel VBA: WorksheetFunction.Gamma Go: math.Gamma Java: ___ JavaScript: ___ Kotlin: ___ PHP: ___ Python: math.gamma R: gamma Ruby: Math.gamma Rust: ___ Scala: ___ Swift: tgamma UFL: Erf [error function][note: Erf(0) = 0, Erf(2) = 0.995322..., Erf(-2) = -0.995322...] AutoHotkey: ___ C++: erf C#: ___ Crystal: Math.erf Excel: ERF Excel VBA: WorksheetFunction.Erf Go: math.Erf Java: ___ JavaScript: ___ Kotlin: ___ PHP: ___ Python: math.erf R: ___ [can use: vValue = 2*pnorm(vNum*sqrt(2)) - 1] Ruby: Math.erf Rust: ___ Scala: ___ Swift: erf UFL: (Pi) [constant or function][pi=3.1415926535...][for a circle: diameter * pi = circumference] AutoHotkey: ___ [can use: vPi := 4*ATan(1)] C++: ___ [e.g. vPi = std::numbers::pi] [also: M_PI, 4*atan(1), acos(-1), atan2(0, -1)] C#: ___ [e.g. vPi = Math.PI] Crystal: ___ [e.g. vPi = Math::PI] Excel: PI [e.g. PI()] Excel VBA: WorksheetFunction.Pi [e.g. vPi = WorksheetFunction.Pi()] [also: vPi = 4*Atn(1)] Go: ___ [e.g. vPi := math.Pi] Java: ___ [e.g. vPi = Math.PI] JavaScript: ___ [e.g. vPi = Math.PI] Kotlin: ___ [e.g. vPi = kotlin.math.PI] PHP: pi [e.g. $vPi = pi()] [also: $vPi = M_PI] Python: ___ [e.g. vPi = math.pi] R: ___ [e.g. vPi = pi] Ruby: ___ [e.g. vPi = Math::PI] Rust: ___ [e.g. vPi = std::f64::consts::PI] Scala: ___ [e.g. vPi = math.Pi] Swift: ___ [e.g. vPi = Double.pi] [also: Float.pi, CGFloat.pi] UFL: (NaN) [generate a NaN (not a number)][note: any NaN, it doesn't matter which] AutoHotkey: ___ [can use: vNaN := Abs(Ln(0)/Ln(0))] [can use: vNaN := -(Ln(0)/Ln(0))] [note: Ln(0) = -infinity] C++: ___ [e.g. vNaN = std::numeric_limits<double>::quiet_NaN()] C#: ___ [e.g. vNaN = Double.NaN] [also: Double.Parse("NaN")] Crystal: ___ [e.g. vNaN = Float64::NAN] [also: "NaN".to_f] Excel: ___ Excel VBA: ___ [can use: vNaN = 0# / 0#] [beforehand: Dim vNaN As Double] [beforehand: On Error Resume Next] Go: math.NaN [e.g. vNaN := math.NaN()] [also: vNaN, _ := strconv.ParseFloat("NaN", 64)] Java: ___ [e.g. vNaN = Double.NaN] [also: Double.parseDouble("NaN")] JavaScript: ___ [e.g. vNaN = NaN] [also: parseFloat("NaN")] Kotlin: ___ [e.g. vNaN = Double.NaN] PHP: ___ [e.g. $vNaN = NAN] [WARNING: floatval("NAN") returns 0, related: 'NaN and Infinity will always be zero when cast to int.'] Python: ___ [e.g. vNaN = float("nan")] [e.g. vNaN = float("NaN")] R: ___ [e.g. vNaN = NaN] [also: as.numeric("NaN")] [note: NA and NaN are different] Ruby: ___ [e.g. vNaN = Float::NAN] Rust: ___ [e.g. vNaN = std::f64::NAN] [also: "NaN".parse::<f64>().unwrap()] Scala: ___ [e.g. vNaN = Double.NaN] [also: "NaN".toDouble] Swift: ___ [e.g. vNaN = Double.nan] [also: vNaN = Double("nan")!] [also: vNaN = Double(nan:0, signaling:false)] UFL: (Infinity) [or PsvInfinity/PositiveInfinity][generate positive infinity] AutoHotkey: ___ [e.g. vInf := Abs(Ln(0))] [e.g. vInf := -Ln(0)] C++: ___ [e.g. vInf = std::numeric_limits<double>::infinity()] C#: ___ [e.g. vInf = Double.PositiveInfinity] [also: Double.Parse("Infinity")] Crystal: ___ [e.g. vInf = Float64::INFINITY] [also: "Infinity".to_f] [also: "Inf".to_f] Excel: ___ Excel VBA: ___ [can use: vInf = 1# / 0#] [beforehand: Dim vInf As Double] [beforehand: On Error Resume Next] Go: math.Inf [e.g. vInf := math.Inf(1)] [also: vInf, _ := strconv.ParseFloat("Inf", 64)] Java: ___ [e.g. vInf = Double.POSITIVE_INFINITY] [also: Double.parseDouble("Infinity")] JavaScript: ___ [e.g. vInf = Infinity] [also: parseFloat("Infinity")] [WARNING: parseFloat is case-sensitive, e.g. 'infinity' would return a NaN] Kotlin: ___ [e.g. vInf = Double.POSITIVE_INFINITY] PHP: ___ [e.g. $vInf = INF] [WARNING: floatval("INF") returns 0, related: 'NaN and Infinity will always be zero when cast to int.'] Python: ___ [e.g. vInf = float("inf")] [e.g. vInf = float("Inf")] R: ___ [e.g. vInf = Inf] [also: as.numeric("Inf")] Ruby: ___ [e.g. vInf = Float::INFINITY] Rust: ___ [e.g. vInf = std::f64::INFINITY] [also: "inf".parse::<f64>().unwrap()] Scala: ___ [e.g. vInf = Double.PositiveInfinity] [also: "Infinity".toDouble] Swift: ___ [e.g. vInf = Double.infinity] [also: vInf = Double("infinity")!] [also: vInf = Double("inf")!] UFL: (NgvInfinity) [or NegativeInfinity][generate negative infinity] AutoHotkey: ___ [e.g. vNInf := -Abs(Ln(0))] [e.g. vNInf := Ln(0)] C++: ___ [e.g. vNInf = -std::numeric_limits<double>::infinity()] C#: ___ [e.g. vNInf = Double.NegativeInfinity] [also: Double.Parse("-Infinity")] Crystal: ___ [e.g. vNInf = -Float64::INFINITY] [also: "-Infinity".to_f] [also: "-Inf".to_f] Excel: ___ Excel VBA: ___ [can use: vNInf = -1# / 0#] [beforehand: Dim vNInf As Double] [beforehand: On Error Resume Next] Go: math.Inf [e.g. vNInf := math.Inf(-1)] [also: vNInf, _ := strconv.ParseFloat("-Inf", 64)] Java: ___ [e.g. vNInf = Double.NEGATIVE_INFINITY] [also: Double.parseDouble("-Infinity")] JavaScript: ___ [e.g. vNInf = -Infinity] [also: parseFloat("-Infinity")] [WARNING: parseFloat is case-sensitive, e.g. 'infinity' would return a NaN] Kotlin: ___ [e.g. vNInf = Double.NEGATIVE_INFINITY] PHP: ___ [e.g. $vNInf = -INF] [WARNING: floatval("-INF") returns 0, related: 'NaN and Infinity will always be zero when cast to int.'] Python: ___ [e.g. vNInf = float("-inf")] [e.g. vNInf = float("-Inf")] R: ___ [e.g. vNInf = -Inf] [also: as.numeric("-Inf")] Ruby: ___ [e.g. vNInf = -Float::INFINITY] Rust: ___ [e.g. vNInf = -std::f64::INFINITY] [also: "-inf".parse::<f64>().unwrap()] Scala: ___ [e.g. vNInf = Double.NegativeInfinity] [also: "-Infinity".toDouble] Swift: ___ [e.g. vNInf = -Double.infinity] [also: vNInf = Double("-infinity")!] [also: vNInf = Double("-inf")!] UFL: IsNaN/IsFinite/IsInfinite [note: NaN: not a number] AutoHotkey: ___/___/___ C++: isnan/isfinite/isinf [i.e. C99 isnan/isfinite/isinf macros] C#: IsNaN/IsFinite/IsInfinity [note: 'IsInfinity' ends with 'y', not 'e'] Crystal: nan/finite/infinite [e.g. returns bool: vNum.nan?] [e.g. returns bool: vNum.finite?] [e.g. returns 1/-1/nil: vNum.infinite?] Excel: ___/___/___ Excel VBA: ___/___/___ Go: math.IsNaN/___/math.IsInf Java: Double.isNaN/Double.isFinite/Double.isInfinite [e.g. Double.isNaN(vNum)] [e.g. Double.isFinite(vNum)] [e.g. Double.isInfinite(vNum)] JavaScript: isNaN/___/___ Kotlin: isNaN/isFinite/isInfinite PHP: is_nan/is_finite/is_infinite Python: math.isnan/math.isfinite/math.isinf R: is.nan/is.finite/is.infinite Ruby: nan/finite/infinite [e.g. returns bool: vNum.nan?] [e.g. returns bool: vNum.finite?] [e.g. returns 1/-1/nil: vNum.infinite?] Rust: is_nan/is_finite/is_infinite Scala: vNum.isNaN/vNum.isFinite/vNum.isInfinite Swift: isnan/isfinite/isinf UFL: (NgvZero) [or NegativeZero][generate negative zero] AutoHotkey: ___ [e.g. vNZ := -0.0] C++: ___ [e.g. vNZ = -0.0] C#: ___ [e.g. vNZ = -0.0] [WARNING: in versions before C# 9 (.NET 5), Console.WriteLine(-0.0) prints '0', it now prints '-0'] Crystal: ___ [e.g. vNZ = -0.0] Excel: ___ [note: negative 0 can be obtained by using a custom VBA function in a cell formula, e.g. =MyNZ()] [e.g. VBA function: Function MyNZ(): MyNZ = -0#: End Function] [note: displays as '-0'] Excel VBA: ___ [e.g. vNZ = -0#] [WARNING: Debug.Print -0# prints '0'] Go: ___ [can use: vNZ := math.Copysign(0.0, -1)] [MAJOR WARNING: -0.0 returns 0.0] [also: vNZ := strconv.ParseFloat("-0.0", 64)] Java: ___ [e.g. vNZ = -0.0] JavaScript: ___ [e.g. vNZ = -0.0] Kotlin: ___ [e.g. vNZ = -0.0] PHP: ___ [e.g. $vNZ = -0.0] Python: ___ [e.g. vNZ = -0.0] R: ___ [e.g. vNZ = -0.0] [WARNING: print(-0.0) prints '0'] [note: sprintf("%f", -0.0) returns '-0.000000'] Ruby: ___ [e.g. vNZ = -0.0] Rust: ___ [e.g. vNZ = -0.0] Scala: ___ [e.g. vNZ = -0.0] Swift: ___ [e.g. vNZ = -0.0] UFL: (IsNgvZero) [or IsNegativeZero][check if a number is negative zero][see also: SignBit] AutoHotkey: ___ [can use: vIsNZ := vNum ? 0 : !!DllCall("msvcrt\atan2", "Double",0, "Double",vNum, "Cdecl Double")] [note: atan2 returns pi for x=-0.0, returns 0 for x=0.0] [also: msvcrt\_copysign] C++: ___ [can use: vIsNZ = (vNum == 0) && std::signbit(vNum)] C#: ___ [can use: vIsNZ = (vNum == 0) && Double.IsNegative(vNum)] [also: vIsNZ = (vNum == 0) && (1.0/vNum < 0)] Crystal: ___ [can use: vIsNZ = (vNum == 0) && (1/vNum < 0)] Excel: ___ [can use: AND(A1+0=0,N(A1)<>0)] [note: =A1+0 and =0+A1 return 0 when A1 is negative zero] [note: N() prevents false positives with strings '-0' and '-0.0'] Excel VBA: ___ [can use: vIsNZ = (vNum = 0) And (WorksheetFunction.Text(vNum, "") = "-")] [also (1/num): vIsNZ = (vNum = 0) And (vTemp < 0)] [beforehand (1/num): Dim vTemp As Double: On Error Resume Next: vTemp = 1 / CDbl(vNum)] Go: ___ [can use: vIsNZ := (vNum == 0) && math.Signbit(vNum)] [MAJOR WARNING: -0.0 returns 0.0] [can use: vNZ := math.Copysign(0.0, -1)] Java: ___ [can use: vIsNZ = (vNum == 0) && (Math.copySign(1.0, vNum) < 0)] JavaScript: ___ [can use: vIsNZ = (vNum === 0) && (1/vNum < 0)] [also: vIsNZ = (vNum === 0) && (1/vNum === -Infinity)] Kotlin: ___ [can use: vIsNZ = (vNum == 0.0) && (Math.copySign(1.0, vNum) < 0.0)] [WARNING: (0.0).equals(-0.0) returns false] [note: (0.0 == -0.0) returns true] PHP: ___ [can use: $vIsNZ = ($vNum == 0) && ($vNum ** -1 < 0)] [also: $vIsNZ = ($vNum == 0) && ($vNum ** -1 == -INF)] Python: ___ [can use: vIsNZ = (vNum == 0) and (math.copysign(1, vNum) < 0)] R: ___ [can use: vIsNZ = (vNum == 0) && (1/vNum < 0)] Ruby: ___ [can use: vIsNZ = (vNum == 0) && (1/vNum < 0)] [also: vIsNZ = (vNum == 0) && (vNum.angle != 0)] Rust: ___ [can use: vIsNZ = (vNum == 0.0) && vNum.is_sign_negative()] Scala: ___ [can use: vIsNZ = (vNum == 0) && (math.copySign(1.0, vNum) < 0)] Swift: ___ [can use: vIsNZ = (vNum == 0.0) && ((vNum).sign == .minus)] UFL: Max [functions listed here can take numbers directly, and can handle more than 2 numbers][see also: Array.Max/Array.StrMax] AutoHotkey: Max [e.g. Max(1, 2, 3)] C++: ___ [note: fmax handles 2 numbers e.g. fmax(1, 2)] C#: ___ [note: Math.Max handles 2 numbers e.g. Math.Max(1, 2)] Crystal: ___ [note: Math.max handles 2 numbers e.g. Math.max(1, 2)] Excel: MAX [e.g. MAX(1,2,3)] Excel VBA: WorksheetFunction.Max [e.g. WorksheetFunction.Max(1,2,3)] Go: max [e.g. max(1, 2, 3)] [note: math.Max handles 2 numbers e.g. math.Max(1, 2)] Java: ___ [note: Math.max handles 2 numbers e.g. Math.max(1, 2)] JavaScript: Math.max [e.g. Math.max(1, 2, 3)] Kotlin: ___ [note: Math.max handles 2 numbers e.g. Math.max(1, 2)] PHP: max [e.g. max(1, 2, 3)] Python: max [e.g. max(1, 2, 3)] R: max [e.g. max(1, 2, 3)] Ruby: ___ Rust: ___ [note: max handles 2 numbers e.g. 1.max(2)] Scala: ___ [note: math.max handles 2 numbers e.g. math.max(1, 2)] Swift: max [e.g. max(1, 2, 3)] UFL: Min [functions listed here can take numbers directly, and can handle more than 2 numbers][see also: Array.Min/Array.StrMin] AutoHotkey: Min [e.g. Min(1, 2, 3)] C++: ___ [note: fmin handles 2 numbers e.g. fmin(1, 2)] C#: ___ [note: Math.Min handles 2 numbers e.g. Math.Min(1, 2)] Crystal: ___ [note: Math.min handles 2 numbers e.g. Math.min(1, 2)] Excel: MIN [e.g. MIN(1,2,3)] Excel VBA: WorksheetFunction.Min [e.g. WorksheetFunction.Min(1,2,3)] Go: min [e.g. min(1, 2, 3)] [note: math.Min handles 2 numbers e.g. math.Min(1, 2)] Java: ___ [note: Math.min handles 2 numbers e.g. Math.min(1, 2)] JavaScript: Math.min [e.g. Math.min(1, 2, 3)] Kotlin: ___ [note: Math.min handles 2 numbers e.g. Math.min(1, 2)] PHP: min [e.g. min(1, 2, 3)] Python: min [e.g. min(1, 2, 3)] R: min [e.g. min(1, 2, 3)] Ruby: ___ Rust: ___ [note: min handles 2 numbers e.g. 1.min(2)] Scala: ___ [note: math.min handles 2 numbers e.g. math.min(1, 2)] Swift: min [e.g. min(1, 2, 3)] UFL: (Sum) [sum n numbers][see also: Array.Sum] AutoHotkey: ___ C++: ___ C#: ___ Crystal: ___ Excel: SUM Excel VBA: WorksheetFunction.Sum Go: ___ Java: ___ [note: Integer.sum handles 2 numbers] JavaScript: ___ [note: Math.addExact handles 2 numbers] Kotlin: ___ [note: Integer.sum handles 2 numbers] PHP: ___ Python: sum R: sum Ruby: ___ Rust: ___ Scala: ___ [note: Integer.sum handles 2 numbers] [e.g. Integer.sum(vNum1, vNum2)] Swift: ___ UFL: (Product) [multiply n numbers][see also: Array.Product] AutoHotkey: ___ C++: ___ C#: ___ Crystal: ___ Excel: PRODUCT Excel VBA: WorksheetFunction.Product Go: ___ Java: ___ JavaScript: ___ [note: Math.multiplyExact handles 2 numbers] Kotlin: ___ PHP: ___ Python: math.prod R: prod Ruby: ___ Rust: ___ Scala: ___ Swift: ___ UFL: (Mean) [see also: Array.Mean] AutoHotkey: ___ C++: ___ C#: ___ Crystal: ___ Excel: AVERAGE Excel VBA: WorksheetFunction.Average Go: ___ Java: ___ JavaScript: ___ Kotlin: ___ PHP: ___ Python: statistics.mean R: ___ [WARNING: mean() expects a vector, not raw numbers] Ruby: ___ Rust: ___ Scala: ___ Swift: ___ UFL: (Median) [see also: Array.Median] AutoHotkey: ___ C++: ___ C#: ___ Crystal: ___ Excel: MEDIAN Excel VBA: WorksheetFunction.Median Go: ___ Java: ___ JavaScript: ___ Kotlin: ___ PHP: ___ Python: statistics.median R: ___ [WARNING: median() expects a vector, not raw numbers] Ruby: ___ Rust: ___ Scala: ___ Swift: ___ UFL: (Mode) [or Modes][note: return all mode values][see also: Array.Mode] AutoHotkey: ___ C++: ___ C#: ___ Crystal: ___ Excel: MODE.MULT [WARNING: MODE: returns the first mode, and fails if the first mode has frequency 1] Excel VBA: WorksheetFunction.Mode_Mult [WARNING: WorksheetFunction.Mode: requires an array, returns the first mode, and fails if the first mode has frequency 1] Go: ___ Java: ___ JavaScript: ___ Kotlin: ___ PHP: ___ Python: statistics.multimode R: ___ [WARNING: mode() returns the variable's 'mode', somewhat like typeof()/class()] [note: to calculate the mode(s), can use either table() or tabulate(), see Array.Mode] Ruby: ___ Rust: ___ Scala: ___ Swift: ___ UFL: (AddSafe)/(SubSafe)/(MulSafe)/(DivSafe)/(PowSafe) [throw if overflow/underflow] AutoHotkey: ___/___/___/___/___ C++: ___/___/___/___/___ C#: ___/___/___/___/___ Crystal: ___/___/___/___/___ Excel: ___/___/___/___/___ Excel VBA: ___/___/___/___/___ Go: ___/___/___/___/___ Java: ___/___/___/___/___ JavaScript: ___/___/___/___/___ Kotlin: ___/___/___/___/___ PHP: ___/___/___/___/___ Python: ___/___/___/___/___ R: ___/___/___/___/___ Ruby: ___/___/___/___/___ Rust: checked_add/checked_sub/checked_mul/checked_div/checked_pow [also: checked_add_unsigned/checked_sub_unsigned] Scala: math.addExact/math.subtractExact/math.multiplyExact/___/___ Swift: ___/___/___/___/___ UFL: RandomInt [random(a,b) inclusive][ideally with a separate RandomSeed function] AutoHotkey: Random [e.g. Random(vMin, vMax)] C++: ___ [can use (inclusive end): vMin + rand() % (vMax-vMin+1)] [beforehand: srand((time(0)))] [WARNING: biased results] [WARNING: RAND_MAX can be small] C#: Next [can use (inclusive end): oRand.Next(vMin, vMax+1)] [beforehand: Random oRand = new Random()] [also (exclusive end): oRand.Next(vMin, vMax)] Crystal: rand [e.g. rand(vMin..vMax)] Excel: RANDBETWEEN [e.g. RANDBETWEEN(vMin,vMax)] Excel VBA: WorksheetFunction.RandBetween [e.g. WorksheetFunction.RandBetween(vMin, vMax)] Go: rand.IntN [e.g. vMin + rand.IntN(vMax-vMin+1)] [note: rand.IntN(vNum) returns an int between 0 and vNum-1 inclusive] Java: ___ [can use (inclusive end): vMin + oRand.nextInt(vMax-vMin+1)] [beforehand: Random oRand = new Random()] [requires: import java.util.Random] JavaScript: ___ [can use (inclusive end): vMin + Math.floor(Math.random()*(vMax-vMin+1))] Kotlin: random [e.g. (vMin..vMax).random()] [also: nextInt and other 'nextXXX' methods] PHP: rand [e.g. rand($vMin, $vMax)] [also: random_int()] Python: random.randint [e.g. random.randint(vMin, vMax)] [also (exclusive end): random.randrange e.g. random.randrange(vMin, vMax+1)] R: sample [e.g. sample(vMin:vMax, 1)] [also (get multiple values): oVec = sample(vMin:vMax, vCount, replace=TRUE)] [also: vMin-1+sample.int(vMax-vMin+1, 1)] [also (get multiple values, note: vector+num increments all items): oVec = sample.int(vMax-vMin+1, vCount, replace=TRUE) + (vMin-1)] Ruby: rand [e.g. rand(vMin..vMax)] Rust: ___ [e.g. let vNum: i64 = oRNG.gen_range(vMin..=vMax)] [beforehand: let mut oRNG = rand::thread_rng()] [requires: use rand::prelude::*] Scala: ___ [can use (inclusive end): Random.between(vMin, vMax+1)] [requires: import scala.util.Random] Swift: random [e.g. Int.random(in:vMin...vMax)] UFL: (RandomIntDemo) [e.g. roll a die (dice): an integer between 1 and 6 inclusive] AutoHotkey: Random [e.g. Random(1, 6)] C++: ___ [e.g. 1 + rand() % 6] C#: Next [e.g. oRand.Next(1, 6+1)] Crystal: rand [e.g. rand(1..6)] Excel: RANDBETWEEN [e.g. RANDBETWEEN(1,6)] Excel VBA: WorksheetFunction.RandBetween [e.g. WorksheetFunction.RandBetween(1, 6)] Go: rand.IntN [e.g. 1 + rand.IntN(6)] Java: ___ [e.g. 1 + oRand.nextInt(6)] JavaScript: ___ [e.g. 1 + Math.floor(Math.random()*6)] Kotlin: random [e.g. (1..6).random()] PHP: rand [e.g. rand(1, 6)] Python: random.randint [e.g. random.randint(1, 6)] [also (exclusive end): e.g. random.randrange(1, 6+1)] R: sample [e.g. sample(1:6, 1)] [also (get multiple values): oVec = sample(1:6, vCount, replace=TRUE)] [also: sample.int(6, 1)] [also (get multiple values): oVec = sample.int(6, vCount, replace=TRUE)] Ruby: rand [e.g. rand(1..6)] Rust: ___ [e.g. let vNum: i64 = oRNG.gen_range(1..=6)] [beforehand: let mut oRNG = rand::thread_rng()] [requires: use rand::prelude::*] Scala: ___ [e.g. Random.between(1, 6+1)] Swift: random [e.g. Int.random(in:1...6)] UFL: RandomFloat [ideally with a separate RandomSeed function][e.g. a number between 0 (inclusive) and 1 (exclusive)] AutoHotkey: Random [e.g. Random()] [WARNING (max): 'generally': 'For floating point numbers, the maximum value is generally excluded.'] C++: ___ [can use: (double)rand()/(double)RAND_MAX] [beforehand: srand((time(0)))] [WARNING (max): can return 1.0] [WARNING: RAND_MAX can be small (i.e. large gaps between possible values)] C#: NextDouble [e.g. oRand.NextDouble()] [beforehand: Random oRand = new Random()] Crystal: ___ [e.g. rand] [e.g. rand()] [also: rand(0.0...1.0)] Excel: RAND [e.g. RAND()] Excel VBA: Rnd [e.g. Rnd()] Go: rand.Float64 [e.g. rand.Float64()] Java: Math.random [e.g. Math.random()] JavaScript: Math.random [e.g. Math.random()] Kotlin: Math.random [e.g. Math.random()] [also: nextDouble and other 'nextXXX' methods] PHP: ___ [can use: $vNum = mt_rand(0, mt_getrandmax()-1) / mt_getrandmax()] [also: lcg_value() (WARNING (max): 0.0 to 1.0 inclusive)] Python: random.random [e.g. random.random()] R: ___ [e.g. runif(1)] [also (multiple values): oVec = runif(vCount, vMin, vMax)] [WARNING (max): min/max values are both exclusive (typically a min is inclusive)] Ruby: ___ [e.g. rand] [e.g. rand()] [also: rand(0.0...1.0)] Rust: ___ [e.g. let vNum: f64 = oRNG.gen()] [beforehand: let mut oRNG = rand::thread_rng()] [requires: use rand::prelude::*] Scala: math.random [e.g. math.random] Swift: random [e.g. Double.random(in:0..<1)]

The Universal Function Library Project: Details

Notes: Function names, parameter names, parameter order, and functionality recommendations, are approximate suggestions; there may be good arguments for alternatives. Function names in parentheses are regarded as somewhat or considerably lower priority. Many example functions are available at JEE.js, the function library that powers this website. Author's Intro: Functions that I would like to see more widely in particular are: FloorMod. For FloorMod(a,b), where b is positive, the return value is always 0 or positive. It is extremely convenient. It is worth implementing both as a function and as an operator (e.g. %%), to enable the easier migration of code between programming languages. Sign and Clamp are highly convenient, reduce bugs, and make the intention clear. Some languages use **, some use Pow. I would recommend implementing both, to enable the easier migration of code between programming languages, and to avoid the rearranging of formulae which is a major source of bugs. I would recommended TrueDiv/IntDiv/FloorDiv functions, and operators (e.g. / ~/ and //, or an alternative for floor division if // is unavailable), to enable the easier migration of code between programming languages, and to avoid terrible/catastrophic bugs. VerCompare/IPCompare functions are highly convenient. PopCount functions are very useful for algorithms, and could be more widely available. They are often used in tight loops, so having them built-in is advantageous performance-wise. An MRound function can be quite convenient (round to the nearest multiple of n). Of the more advanced functions, Combin/Permut, Gamma and Erf are worth considering, for their general utility. And just between you and me... Between: The 'between' debate has raged for decades: Introducing chained operators can allow 'a <= x <= b', but typically creates other unreadable/unpredictable/dangerous combinations of operators. Doing '(a <= x) && (x <= b)', repeats x. And x could be long or an expression. I have found it very convenient to have a Between function e.g. 'Between(x, a, b)'. A BetweenUntil function could also be implemented. It avoids the repeating of expressions, it makes it easy to find instances of 'between' comparisons in code, it avoids questions of how to order the operands. Its power can be increased by accepting a comparator function. UFL notes: Abs/Sign [note: return 1/0/-1, -0.0 returns -0.0, NaN returns NaN] recommendation: Sign: maintain the type of the number recommendation: Sign: for floats, maintain positive/negative 0 UFL notes: Pow UFL notes: Sqrt/(Cbrt) recommendation: having a Cbrt function helps maintain exact values across different programming languages UFL notes: Round [round to the nearest integer (or round to n decimal places)] UFL notes: Ceil/Floor [round up towards +infinity, round down towards -infinity] UFL notes: Trunc [truncate: round towards zero (remove the fractional part)] UFL notes: Log/Ln/Log10/(Log2) [where Log allows you to specify the base] recommendation: having additional Log functions helps maintain exact values across different programming languages UFL notes: Exp UFL notes: Max/Min [functions listed here can handle more than 2 numbers] UFL notes: Clamp UFL notes: Between/(BetweenUntil) [Between: a <= x <= b, BetweenUntil: a <= x < b] format: Between(Needle, Bound1, Bound2, Comparator:=unset) recommendation: accepting a comparator function could allow for strings/version number strings/IP address strings to be compared recommendation: SAFETY: it may be better to have separate (numerical) Between and StrBetween functions (alternatively, the function could throw if no comparator is specified, and a non-number is passed) UFL notes: Mod/FloorMod UFL notes: IntDiv/FloorDiv [divide then round towards zero (remove the fractional part), divide round down towards -infinity] UFL notes: (Hypot) UFL notes: (Fact) [factorial] UFL notes: (IsPrime)/(Triang)/(Fib) [is prime/triangular number/Fibonacci number] UFL notes: (DegToRad)/(RadToDeg) UFL notes: (Sum)/(Product) UFL notes: (Mean)/(Median)/(Mode) [Mode: return all mode values] recommendation: implement a version of Mode that returns all the mode values as an array UFL notes: Sin/Cos/Tan/(SinDeg)/(CosDeg)/(TanDeg) recommendation: 'Deg' variants make it simpler to do calculations in degrees UFL notes: ASin/ACos/ATan/(ASinDeg)/(ACosDeg)/(ATanDeg) recommendation: 'Deg' variants make it simpler to do calculations in degrees UFL notes: ATan2/(ATan2Deg) recommendation: 'Deg' variants make it simpler to do calculations in degrees UFL notes: DecToBase/BaseToDec/(DecToBin)/(BinToDec)/(DecToHex)/(HexToDec) recommendation: make it easy to convert between all bases, 2 to 36 recommendation: accepting an object, could facilitate converting between greater bases UFL notes: Combin/Permut [combinations without repetition, permutations without repetition] recommendation: these can be very awkward to implement as custom code, if not built-in (with 'with/without repetition' options) UFL notes: GCD/LCM [GCD ALSO HCF] UFL notes: RandomInt/RandomFloat [ideally with a separate RandomSeed function] UFL notes: (NumCompare) UFL notes: VerCompare [VerCompare ALSO IPCompare][e.g. compare '1.2.3.4' against '1.2', and/or handle SemVer][e.g. compare IP addresses (IPv4 and/or IPv6)] recommendation: an Options parameter could determine whether only '1.2.3.4'-style strings are handled, or whether SemVer, IPv4 and/or IPv6 are handled recommendation: VerCompare/IPCompare could be implemented as separate functions UFL notes: PopCount32/PopCount64 UFL notes: (BitRotateLeft)/(BitRotateRight) UFL notes: (BitAnd)/(BitOr)/(BitXor)/(BitNot) UFL notes: (BitShiftLeft)/(BitShiftRight)/(BitShiftRightLogical) UFL notes: MRound [round to the nearest multiple of n] UFL notes: (Nearest) [return the nearest number: Nearest(vNum, oNums*), e.g. round to the nearest multiple of 5 (an alternative to MRound): Nearest(vNum, vNum-vNum%5, vNum-vNum%5+5)] recommendation: there are various considerations for an options parameter (or separate functions): e.g. nearest greater/lesser/different number, and nearest number (greater/lesser if tiebreak) UFL notes: IsNaN/IsFinite/IsInfinite UFL notes: TrueDiv [or Div/FloatDiv] UFL notes: Gamma UFL notes: Erf