Programming Language Cheat Sheets: Mathematics

Strings Mathematics Operators and Symbols General (Control Flow/Debugging) Dates Objects New Features Timelines 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) AutoHotkey: vNum := 123 [type: Integer] C++: auto vNum = 123 [type: i]['auto'/'int' resolve to i] C#: var vNum = 123 [type: Int32]['var'/'int'/'Int32' resolve to Int32] Crystal: vNum = 123 [type: Int32] Excel: 123 [type: 1 (Number)] Excel VBA: vNum = 123 [type: Integer] Go: Java: var vNum = 123 [type: int]['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: Ruby: vNum = 123 [type: Integer] Rust: let vNum = 123 [type: i32] Swift: var vNum = 123 [type: Int] UFL: (FloatNewDemo) [or DoubleNewDemo] AutoHotkey: vNum := 123.456 [type: Float] C++: auto vNum = 123.456 [type: d]['auto'/'double' resolve to d] C#: var vNum = 123.456 [type: Double]['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: Java: var vNum = 123.456 [type: double]['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: Ruby: vNum = 123.456 [type: Float] Rust: let vNum = 123.456 [type: f64] Swift: var vNum = 123.456 [type: Double] UFL: True/False 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: 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: Ruby: true/false [type: TrueClass/FalseClass] Rust: true/false [type: bool] Swift: true/false [type: Bool] 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 [where A1 contains TRUE or FALSE][note: outputs TRUE/FALSE] Excel VBA: vText = "" & vBool [note: outputs True/False][also: CStr(vBool)] Go: 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: Ruby: vText = vBool.to_s [note: outputs true/false] Rust: vText = vBool.to_string() [note: outputs true/false][also: vText = format!("{}", vBool)] 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: 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: 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 != "")] 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")] 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: 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: Ruby: vBool = (vText.downcase == "true") Rust: vBool = (vText.to_lowercase() == "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: Java: Math.abs JavaScript: Math.abs Kotlin: Math.abs PHP: abs Python: abs [also: math.fabs] R: Ruby: abs [e.g. vNum.abs] Rust: 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] 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: 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] Swift: signum [e.g. vNum.signum()][note: floats lack a signum method] UFL: SignPsvNgv [e.g. returns 1/-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: 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: Ruby: ___ Rust: ___ [can use (for floats): signum][WARNING: for int 0, signum returns 0, not 1] 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 1/0][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: Java: ___ JavaScript: ___ Kotlin: ___ PHP: ___ Python: ___ R: Ruby: ___ Rust: ___ [can use: is_negative/is_sign_negative for ints/floats respectively] Swift: ___ [can use: vSign = ((vNum).sign == .plus) ? 0 : 1] 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: 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: Ruby: ___ [can use: **] Rust: pow [also: powi/powf] Swift: pow 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: Java: Math.sqrt/Math.cbrt JavaScript: Math.sqrt/Math.cbrt Kotlin: Math.sqrt/Math.cbrt PHP: sqrt/___ Python: math.sqrt/math.cbrt R: Ruby: Math.sqrt/Math.cbrt Rust: sqrt/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: 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: Ruby: round [e.g. vInt = vNum.round] Rust: round [e.g. vFloat = vNum.round()] 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: 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: 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)] 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: Java: Math.ceil JavaScript: Math.ceil Kotlin: Math.ceil PHP: ceil Python: math.ceil R: Ruby: ceil [e.g. vNum.ceil] Rust: 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: Java: Math.floor JavaScript: Math.floor Kotlin: Math.floor PHP: floor Python: math.floor R: Ruby: floor [e.g. vNum.floor] Rust: floor Swift: floor UFL: Trunc [truncate (round towards zero) (remove the fractional part)][see also: FloatToInteger] 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: Java: intValue [can use: vDouble.intValue] JavaScript: Math.trunc Kotlin: kotlin.math.truncate PHP: intval Python: int [also: math.trunc] R: Ruby: truncate [e.g. vNum.truncate][also: vNum.to_i] Rust: trunc Swift: trunc [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: 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 FloorMod, e.g. -2.9 % 1 = 0.1, but we want -0.9] R: 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 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: Ruby: ___ Rust: ___ 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: does handle float-like input string] C++: std::stoi [e.g. vNum = std::stoi(vText)][note: does handle float-like input string] C#: Int32.Parse [e.g. vNum = Int32.Parse(vText)][also: Int64.Parse][WARNING: fails if input string looks like a float] Crystal: to_i [e.g. vNum = vText.to_i][WARNING: fails if input string looks like a float] Excel: TRUNC [e.g. TRUNC(A1)][WARNING: Int floors (always rounds down)][note: does handle float-like input string] Excel VBA: CInt [e.g. vNum = CInt(vText)][also: CLng/CLngLng/CLngPtr][note: does handle float-like input string] Go: Java: Integer.parseInt [e.g. vNum = Integer.parseInt(vText)] JavaScript: parseInt [e.g. vNum = parseInt(vText)] Kotlin: toInt [e.g. vNum = vText.toInt()][WARNING: fails if input string looks like a float] PHP: intval [e.g. $vNum = intval($vText)][also: $vNum = (int)$vText][note: does handle float-like input string] Python: int [e.g. vNum = int(vText)][WARNING: fails if input string looks like a float] R: Ruby: to_i [e.g. vNum = vText.to_i] Rust: parse [e.g. vNum: i32 = vText.parse().unwrap()][WARNING: fails if input string looks like a float] Swift: Int [e.g. vNum = Int(vText)!][WARNING: fails if input string looks like a float] 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++: ___ [can use: vNum = (int)vFloat] C#: ___ [can use: 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: Java: ___ [can use: 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: Ruby: to_i [e.g. vNum = vFloat.to_i] Rust: ___ [can use: vNum = vFloat as i32][also: trunc] 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: 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: Ruby: to_f [e.g. vNum = vText.to_f] Rust: parse [e.g. vNum: f64 = vText.parse().unwrap()] Swift: Double [e.g. vNum = Double(vText)!] 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++: ___ [can use: vNum = (double)vInt] C#: ___ [can use: 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: Java: ___ [can use: 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: Ruby: to_f [e.g. vNum = vInt.to_f] Rust: ___ [can use: vNum = vInt as f64] Swift: Double [e.g. vNum = Double(vInt)] UFL: BoolToInt [true to 1, false to 0] 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++: ___ [can use: 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: ___ [can use: A1+0] Excel VBA: CInt [e.g. vNum = CInt(vBool)] Go: 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: Ruby: ___ [can use: vNum = vBool ? 1 : 0] Rust: ___ [can use: vNum = vBool as i32][can use: vNum = if vBool {1} else {0}] Swift: ___ [can use: vNum = vBool ? 1 : 0] UFL: IntToBool [non-zero to true, 0 to false] AutoHotkey: ___ [can use: vBool := !!vNum][also: vBool := vNum ? true : false][note: no bool type: true = 1, false = 0] C++: ___ [can use: 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: Java: ___ [can use: vBool = (vNum != 0)] JavaScript: Boolean [e.g. vBool = Boolean(vNum)][can use: vBool = !!vNum][can use: vBool = (vNum != 0)][can use: 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: 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] Swift: ___ [can use: vBool = (vNum != 0)] UFL: Log [base must be specified unless stated][WARNING: bases 10 and e (e=2.718...) 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: 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: Ruby: Math.log [WARNING: uses base e if base omitted] Rust: log [note: base must be specified] 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: 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: Ruby: Math.log/Math.log10/Math.log2 Rust: ln/log10/log2 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...)] AutoHotkey: Exp C++: exp C#: Math.Exp Crystal: Math.exp Excel: EXP Excel VBA: Exp Go: Java: Math.exp JavaScript: Math.exp Kotlin: Math.exp PHP: exp Python: math.exp R: Ruby: Math.exp Rust: exp Swift: exp UFL: Clamp [clamp a number, e.g. clamp volume between 0 and 100 inclusive][equivalent to obtaining the median of 3 numbers] AutoHotkey: ___ 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(A1,vMin,vMax)] Excel VBA: ___ [can use: vNumNew = WorksheetFunction.Median(vNum, vMin, vMax)] Go: 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: ___ Python: ___ [can use: statistics.median([vNum, vMin, vMax])][also (median): vNumNew = sorted([vNum, vMin, vMax])[1]][requires (statistics.median): import statistics] R: 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)] 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)] 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: 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] Swift: ___ UFL: (BetweenUntil) [a <= x < b][is number between limits (exclusive end)] 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: ___ Swift: ___ 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: 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] 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: 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: floor mod, not C-style mod)] R: Ruby: modulo [e.g. vNum1.modulo(vNum2)][also: % (WARNING: floor mod, not C-style mod)] Rust: ___ Swift: ___ UFL: IntDiv [or TruncDiv][divide then round towards zero (remove the fractional part)][e.g. Dart uses ~/] AutoHotkey: ___ [can use (trunc. div.) (AHK v2): // (WARNING: differs from Python)] C++: ___ C#: ___ Crystal: ___ [can use: (vNum1/vNum2).to_i] Excel: QUOTIENT [e.g. QUOTIENT(A1,vNum)] Excel VBA: WorksheetFunction.Quotient [e.g. WorksheetFunction.Quotient(vNum1, vNum2)] Go: Java: ___ JavaScript: ___ Kotlin: ___ PHP: intdiv [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: 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: ___ Swift: ___ UFL: FloorDiv [divide then round down (towards -infinity)][e.g. Python uses //] AutoHotkey: ___ [WARNING: in AHK v1, but not AHK v2: // did floor division, if at least one value was a float (WARNING: differs from Python)] C++: ___ C#: ___ Crystal: ___ [can use: (vNum1/vNum2).floor][also: divmod (returns quotient and remainder as an array), e.g. vNum1.divmod(vNum2)[0]] Excel: ___ Excel VBA: ___ Go: Java: Math.floorDiv JavaScript: ___ Kotlin: Math.floorDiv PHP: ___ Python: operator.floordiv [can use: //][also: divmod (returns quotient and remainder as a tuple), e.g. divmod(vNum1, vNum2)[0]] R: Ruby: ___ [can use: (vNum1/vNum2).floor][also: divmod (returns quotient and remainder as an array), e.g. vNum1.divmod(vNum2)[0]][note: for ints, can just do: vNum1/vNum2] Rust: ___ Swift: ___ 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: Java: Math.hypot JavaScript: Math.hypot Kotlin: Math.hypot PHP: hypot Python: math.hypot R: Ruby: Math.hypot Rust: 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: Ruby: ___ Rust: ___ 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: ___ 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: ___ Swift: ___ UFL: (Fib) [Fibonacci number] AutoHotkey: ___ C++: ___ C#: ___ Crystal: ___ Excel: ___ Excel VBA: ___ Go: Java: ___ JavaScript: ___ Kotlin: ___ PHP: ___ Python: ___ R: Ruby: ___ Rust: ___ 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 Swift: ___/___ UFL: Sin/Cos/Tan 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: 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: Ruby: Math.sin/Math.cos/Math.tan Rust: sin/cos/tan Swift: sin/cos/tan UFL: ASin/ACos/ATan 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: 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: Ruby: Math.asin/Math.acos/Math.atan Rust: asin/acos/atan Swift: asin/acos/atan UFL: ATan2 [note: the (y,x) parameter order matches the common calculation: ATan(y/x)] 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: 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: Ruby: Math.atan2 [note: parameters: y, x] Rust: atan2 [note: parameters: y, x][e.g. vNumY.atan2(vNumX)] 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: ___/___/___/___/___/___/___ 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: 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: 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)] 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)][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: 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: Ruby: to_i [e.g. vText.to_i(vBase)] Rust: from_str_radix [e.g. i32::from_str_radix(vText, vBase).unwrap()] 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: Java: Integer.toBinaryString JavaScript: ___ [can use: toString] Kotlin: Integer.toBinaryString PHP: decbin Python: bin R: Ruby: to_s [e.g. vNum.to_s(2)] Rust: ___ [can use: format] 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: Java: ___ [can use: Integer.parseInt] JavaScript: ___ [can use: parseInt] Kotlin: ___ [can use: Integer.parseInt] PHP: bindec Python: ___ [can use: int] R: Ruby: to_i [e.g. vText.to_i(2)] Rust: ___ [can use: from_str_radix] 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: Java: Integer.toHexString JavaScript: ___ [can use: toString] Kotlin: Integer.toHexString PHP: dechex Python: hex R: Ruby: to_s [e.g. vNum.to_s(16)] Rust: ___ [can use: format] 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: Java: ___ [can use: Integer.parseInt] JavaScript: ___ [can use: parseInt] Kotlin: ___ [can use: Integer.parseInt] PHP: hexdec Python: ___ [can use: int] R: Ruby: to_i [e.g. vText.to_i(16)] Rust: ___ [can use: from_str_radix] 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: Ruby: ___/___ Rust: ___/___ 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: ___/___ 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: ___ 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: ___ Swift: ___ UFL: (NumCompare) [note: can typically also use: < > ==] AutoHotkey: ___ C++: ___ [can use: <=>][e.g. int vCmp = (int)std::bit_cast<int8_t>(vNum1 <=> vNum2)] C#: CompareTo Crystal: ___ [can use: <=>][e.g. vCmp = vNum1 <=> vNum2] Excel: ___ Excel VBA: ___ Go: Java: Integer.compare [also: Double.compare] JavaScript: ___ Kotlin: compareValues [also: compareValuesBy] PHP: ___ [can use: <=>][e.g. $vCmp = $vNum1 <=> $vNum2] Python: ___ R: Ruby: ___ [can use: <=>][e.g. vCmp = vNum1 <=> vNum2] Rust: cmp [e.g. vCmp = vNum1.cmp(&vNum2) as i32] 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: Ruby: ___ [can use: <=>][e.g. vCmp = Gem::Version.new(vVersion1) <=> Gem::Version.new(vVersion2)] Rust: ___ Swift: ___ UFL: PopCount32/PopCount64 [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: 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: Ruby: ___ [can use: vNum.to_s(2).count("1")] Rust: count_ones/count_ones 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: And Or Xor] Go: Java: ___/___/___ [can use: & | ^] JavaScript: ___/___/___ [can use: & | ^] Kotlin: ___/___/___ [can use: 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: Ruby: ___/___/___ [can use: & | ^] Rust: ___/___/___ [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: Not][WARNING: Excel VBA's Not is logical not (for bools) and bitwise not (for ints)] Go: Java: ___ [can use: ~] JavaScript: ___ [can use: ~] Kotlin: ___ [can use: inv] PHP: ___ [can use: ~][also: variant_not] Python: operator.invert [also: operator.inv][can use: ~] R: Ruby: ___ [can use: ~] Rust: ___ [can use: !][WARNING: Rust's ! is logical not (for bools) and bitwise not (for ints)] Swift: ___ [can use: ~] UFL: (BitShiftLeft) 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: Java: ___ [can use: <<] JavaScript: ___ [can use: <<] Kotlin: ___ [can use (operator): shl] PHP: ___ [can use: <<] Python: operator.lshift [can use: <<] R: Ruby: ___ [can use: <<] Rust: ___ [can use: <<] Swift: ___ [can use: <<] UFL: (BitShiftRight)/(BitShiftRightLogical) 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: 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: Ruby: ___/___ [can use: >>] Rust: ___/___ [can use: >>] Swift: ___/___ [can use: >>] UFL: (BitRotateLeft)/(BitRotateRight) AutoHotkey: ___/___ C++: ___/___ C#: BitOperations.RotateLeft/BitOperations.RotateRight Crystal: rotate_left/rotate_right Excel: ___/___ Excel VBA: ___/___ Go: Java: Integer.rotateLeft/Integer.rotateRight JavaScript: ___/___ Kotlin: Integer.rotateLeft/Integer.rotateRight PHP: ___/___ Python: ___/___ R: Ruby: ___/___ Rust: rotate_left/rotate_right Swift: ___/___ UFL: MRound [round to the nearest multiple of n] AutoHotkey: ___ C++: ___ C#: ___ Crystal: ___ Excel: MROUND Excel VBA: WorksheetFunction.MRound Go: Java: ___ JavaScript: ___ Kotlin: ___ PHP: ___ Python: ___ R: Ruby: ___ Rust: ___ 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: ___ Swift: ___ 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: Java: Double.isNan/Double.isFinite/Double.isInfinite JavaScript: isNaN/___/___ Kotlin: isNaN/isFinite/isInfinite PHP: is_nan/is_finite/is_infinite Python: math.isnan/math.isfinite/math.isinf R: 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 Swift: isnan/isfinite/isinf 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] AutoHotkey: ___ [can use: /] C++: ___ [WARNING: / on ints uses C-style integer division] C#: ___ [WARNING: / on ints uses C-style integer division] Crystal: ___ [can use: /] Excel: ___ [can use: /] Excel VBA: ___ [can use: /] Go: Java: ___ [WARNING: / on ints uses C-style integer division] JavaScript: ___ [can use: /] Kotlin: ___ [WARNING: / on ints uses C-style integer division] PHP: fdiv [also: /] Python: operator.truediv [also (Python 3 onwards): /][note: Python 1/2: / on ints uses floor division] R: Ruby: ___ [can use: vNum1/vNum2.to_f][WARNING: / on ints uses floor division] Rust: ___ [WARNING: / on ints uses C-style integer division] Swift: ___ [WARNING: / on ints uses C-style integer division] 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: Ruby: ___/___ Rust: ___/___ Swift: ___/___ UFL: Gamma [gamma function][note: gamma(n) is the same as fact(n-1) for integers n > 0][see also: Fact] AutoHotkey: ___ C++: tgamma C#: ___ Crystal: Math.gamma Excel: GAMMA [note: added in Excel 2013] Excel VBA: WorksheetFunction.Gamma Go: Java: ___ JavaScript: ___ Kotlin: ___ PHP: ___ Python: math.gamma R: Ruby: Math.gamma Rust: ___ Swift: tgamma UFL: Erf [error function] AutoHotkey: ___ C++: erf C#: ___ Crystal: Math.erf Excel: ERF Excel VBA: WorksheetFunction.Erf Go: Java: ___ JavaScript: ___ Kotlin: ___ PHP: ___ Python: math.erf R: Ruby: Math.erf Rust: ___ Swift: erf UFL: (Pi) [constant or function] 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: 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: Ruby: ___ [e.g. vPi = Math::PI] Rust: ___ [e.g. vPi = std::f64::consts::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 := -(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: 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")] R: Ruby: ___ [e.g. vNaN = Float::NAN] Rust: ___ [e.g. vNaN = std::f64::NAN][also: "NaN".parse::<f64>().unwrap()] Swift: ___ [e.g. vNaN = Double.nan][also: vNaN = Double("nan")!][also: vNaN = Double(nan:0, signaling:false)] UFL: (Infinity) [generate positive infinity] AutoHotkey: ___ [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: 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")] R: Ruby: ___ [e.g. vInf = Float::INFINITY] Rust: ___ [e.g. vInf = std::f64::INFINITY][also: "inf".parse::<f64>().unwrap()] Swift: ___ [e.g. vInf = Double.infinity][also: vInf = Double("infinity")!][also: vInf = Double("inf")!] UFL: (NgvInfinity) [generate negative infinity] AutoHotkey: ___ [e.g. vNgvInf := Ln(0)] C++: ___ [e.g. vNgvInf = -std::numeric_limits<double>::infinity()] C#: ___ [e.g. vNgvInf = Double.NegativeInfinity][also: Double.Parse("-Infinity")] Crystal: ___ [e.g. vNgvInf = -Float::INFINITY][also: "-Infinity".to_f][also: "-Inf".to_f] Excel: ___ Excel VBA: ___ [can use: vNgvInf = -1# / 0#][beforehand: Dim vNgvInf As Double][beforehand: On Error Resume Next] Go: Java: ___ [e.g. vNgvInf = Double.NEGATIVE_INFINITY][also: Double.parseDouble("-Infinity")] JavaScript: ___ [e.g. vNgvInf = -Infinity][also: parseFloat("-Infinity")][WARNING: parseFloat is case-sensitive, e.g. 'infinity' would return a NaN] Kotlin: ___ [e.g. vNgvInf = Double.NEGATIVE_INFINITY] PHP: ___ [e.g. $vNgvInf = -INF][WARNING: -floatval("INF") returns 0, related: 'NaN and Infinity will always be zero when cast to int.'] Python: ___ [e.g. vNgvInf = -float("Inf")] R: Ruby: ___ [e.g. vNgvInf = -Float::INFINITY] Rust: ___ [e.g. vNgvInf = -std::f64::INFINITY][also: "-inf".parse::<f64>().unwrap()] Swift: ___ [e.g. vNgvInf = -Double.infinity][also: vNgvInf = Double("-infinity")!][also: vNgvInf = Double("-inf")!] UFL: (IsNegativeZero) [or IsNgvZero][check if a number is negative zero][see also: SignBit] AutoHotkey: ___ [can use: vIsNgv0 := 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] C++: ___ [can use: vIsNgv0 = (vNum == 0) && std::signbit(vNum)] C#: ___ [can use: vIsNgv0 = (vNum == 0) && Double.IsNegative(vNum)] Crystal: ___ [can use: vIsNgv0 = (vNum == 0) && (1/vNum < 0)] Excel: ___ [can use: AND(A1+0=0,A1=0)][note: negative 0 can be obtained by using a custom VBA function in a cell formula][note: -0+0=0] Excel VBA: ___ [can use: vIsNgv0 = (vNum = 0) And (vTemp < 0)][beforehand (1): Dim vTemp As Double][beforehand (2): On Error Resume Next][beforehand (3): vTemp = 1 / CDbl(vNum)][note: vNgv0 = -0#] Go: Java: ___ [can use: vIsNgv0 = (vNum == 0) && (Math.copySign(1.0, vNum) < 0)] JavaScript: ___ [can use: vIsNgv0 = (vNum === 0) && (1/vNum === -Infinity)] Kotlin: ___ [can use: vIsNgv0 = (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: $vIsNgv0 = ($vNum == 0) && ($vNum ** -1 == -INF)] Python: ___ [can use: vIsNgv0 = (vNum == 0) and (math.copysign(1, vNum) < 0)] R: Ruby: ___ [can use: vIsNgv0 = (vNum == 0) && (1/vNum < 0)][also: vIsNgv0 = (vNum == 0) && (vNum.angle != 0)] Rust: ___ [can use: vIsNgv0 = (vNum == 0.0) && vNum.is_sign_negative()] Swift: ___ [can use: vIsNgv0 = (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: 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: Ruby: ___ Rust: ___ [note: max handles 2 numbers e.g. 1.max(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: 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: Ruby: ___ Rust: ___ [note: min handles 2 numbers e.g. 1.min(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: Ruby: ___ Rust: ___ 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: Ruby: ___ Rust: ___ 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: Ruby: ___ Rust: ___ 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: Ruby: ___ Rust: ___ Swift: ___ UFL: (Mode) [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: Ruby: ___ Rust: ___ 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] Swift: ___/___/___/___/___ UFL: Range [a <= x <= b][generate numbers a to b (inclusive end)] AutoHotkey: ___ C++: ___ C#: ___ Crystal: ___ [can use .. e.g. (vNum1..vNum2)] Excel: ___ Excel VBA: ___ Go: Java: IntStream.rangeClosed [also: LongStream.rangeClosed] JavaScript: ___ Kotlin: rangeTo [can use: .. (inclusive end)][can use: downTo (like .. but in reverse order)] PHP: range Python: ___ R: Ruby: ___ [can use .. e.g. (vNum1..vNum2)] Rust: ___ [can use: ..= e.g. (vNum1..=vNum2).collect()] Swift: ___ [can use: ... (3 dots)][note: can omit 1 value to create a one-sided range] UFL: (RangeUntil) [a <= x < b][generate numbers a to b (exclusive end)] AutoHotkey: ___ C++: ___ C#: Enumerable.Range [WARNING: Enumerable.Range: exclusive end][can use: .. (WARNING: .. operator: exclusive end)] Crystal: ___ [can use ... e.g. (vNum1...vNum2)] Excel: ___ Excel VBA: ___ Go: Java: IntStream.range [WARNING: IntStream.range: exclusive end][also: LongStream.range] JavaScript: ___/___ Kotlin: rangeUntil [can use: ..<] PHP: range/___ Python: range [WARNING: range: exclusive end] R: Ruby: ___ [can use ... e.g. (vNum1...vNum2)] Rust: ___ [can use: .. e.g. (vNum1..vNum2).collect()][WARNING: .. operator: exclusive end] Swift: ___/___ [can use: ..<][note: can omit 1 value to create a one-sided range] 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(1,6)] Excel VBA: WorksheetFunction.RandBetween [e.g. WorksheetFunction.RandBetween(vMin, vMax)] Go: 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: 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::*] 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: 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: 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::*] 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: 'generally': 'For floating point numbers, the maximum value is generally excluded.'] C++: ___ [can use: (double)rand()/(double)RAND_MAX][beforehand: srand((time(0)))][WARNING: can return 1.0][WARNING: RAND_MAX can be small] 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: 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: 0.0 to 1.0 inclusive)] Python: random.random [e.g. random.random()] R: 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::*] 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 many 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