Programming Language Cheat Sheets: Mathematics

Strings [Format] Mathematics Operators and Symbols General (Control Flow/Debugging) Dates Objects [Range] New Features Timelines Documentation Links 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)][MAJOR WARNING: 'int' types are often 64-bit or 32-bit depending on the platform][see also: VarDeclSet/VarDeclSetAuto] AutoHotkey: vNum := 123 [type: Integer] [note: a signed Int64] C++: auto vNum = 123 [type: i] [also: int vNum = 123] [note: 'auto'/'int' resolve to i] C#: var vNum = 123 [type: Int32] [also: int vNum = 123] [note: 'var'/'int'/'Int32' resolve to Int32] Crystal: vNum = 123 [type: Int32] [also: vNum: Int32 = 123] Excel: 123 [type: 1 (Number)] [MAJOR WARNING: Excel rounds numbers to 15 significant figures as they're typed, workaround: store as strings] Excel VBA: vNum = 123 [type: Integer] Go: vNum := 123 [type: int] [also: var vNum int = 123] [WARNING: 'The int, uint, and uintptr types are usually 32 bits wide on 32-bit systems and 64 bits wide on 64-bit systems.'] Java: var vNum = 123 [type: int] [also: int vNum = 123] [also: Integer vNum = 123] [note: 'var'/'int' resolve to int] [note (int): a signed Int32] JavaScript: vNum = 123 [type: Number] [note: a 64-bit float] Kotlin: var vNum = 123 [type: Int] [also: var vNum: Int = 123] [note (Int): a signed Int32] PHP: $vNum = 123 [type: integer] [WARNING: 'The size of an int is platform-dependent', can check: PHP_INT_MAX and PHP_INT_MIN] Python: vNum = 123 [type: int] [also (type hint): vNum: int = 123] [note: 'Integers have unlimited precision.'] R: vNum = 123 [type: double (class: numeric)] [also: vNum = as.integer(123)] [type (as.integer): integer] Ruby: vNum = 123 [type: Integer] [note (bitwise-not): 'As integers are conceptually of infinite length, the result acts as if it had an infinite number of one bits to the left.'] Rust: let mut vNum = 123 [type: i32] [also: let mut vNum: i32 = 123] Scala: var vNum = 123 [type: int] [also: var vNum: Int = 123] [note: a signed Int32] SQL (MySQL): ___ [can use: INSERT INTO MyTable VALUES ('MyKey', 123)] [type: int] SQL (PostgreSQL): ___ [can use: INSERT INTO MyTable VALUES ('MyKey', 123)] [type: integer] SQL (SQLite): ___ [can use: INSERT INTO MyTable VALUES ('MyKey', 123)] [type: integer] Swift: var vNum = 123 [type: Int] [also: var vNum: Int = 123] [WARNING: 'Int, which has the same size as the current platform’s native word size', 'UInt, which has the same size as the current platform’s native word size'] UFL: (FloatNewDemo) [or DoubleNewDemo][create a float (floating-point number)][see also: VarDeclSet/VarDeclSetAuto] AutoHotkey: vNum := 123.456 [type: Float] C++: auto vNum = 123.456 [type: d] [also: double vNum = 123.456] [note: 'auto'/'double' resolve to d] C#: var vNum = 123.456 [type: Double] [also: double vNum = 123.456] [note: 'var'/'double'/'Double' resolve to Double] Crystal: vNum = 123.456 [type: Float64] [also: vNum: Float64 = 123.456] Excel: 123.456 [type: 1 (Number)] Excel VBA: vNum = 123.456 [type: Double] Go: vNum := 123.456 [type: float64] [also: var vNum float64 = 123.456] Java: var vNum = 123.456 [type: double] [also: double vNum = 123.456] [also: Double vNum = 123.456] [note: 'var'/'double' resolve to double] JavaScript: vNum = 123.456 [type: Number] [note: a 64-bit float] Kotlin: var vNum = 123.456 [type: Double] [also: var vNum: Double = 123.456] PHP: $vNum = 123.456 [type: double] Python: vNum = 123.456 [type: float] [also (type hint): vNum: float = 123.456] R: vNum = 123.456 [type: double (class: numeric)] Ruby: vNum = 123.456 [type: Float] Rust: let mut vNum = 123.456 [type: f64] [also: let mut vNum: f64 = 123.456] Scala: var vNum = 123.456 [type: double] [also: var vNum: Double = 123.456] SQL (MySQL): ___ [can use: INSERT INTO MyTable VALUES ('MyKey', 123.456)] [type: decimal] SQL (PostgreSQL): ___ [can use: INSERT INTO MyTable VALUES ('MyKey', 123.456)] [type: numeric] SQL (SQLite): ___ [can use: INSERT INTO MyTable VALUES ('MyKey', 123.456)] [type: real] Swift: var vNum = 123.456 [type: Double] [also: var vNum: Double = 123.456] UFL: Int64Max [or MaxInt64/IntMax64][create max signed Int64, 0x7FFFFFFFFFFFFFFF = 9223372036854775807][note: if Int64 is unavailable, Float64 is effectively 'Int53'] AutoHotkey: vNum := 0x7FFFFFFFFFFFFFFF [note: AutoHotkey's Integer type is signed Int64] C++: auto vNum = std::numeric_limits<long long>::max() [requires (numeric_limits): #include <limits>] [also: long long vNum = 0x7FFFFFFFFFFFFFFF] [also: long long vNum = ~(unsigned long long)0 >> 1] C#: Int64 vNum = Int64.MaxValue [also: Int64 vNum = 0x7FFFFFFFFFFFFFFF] Crystal: vNum = Int64::MAX [also: vNum = 0x7FFFFFFFFFFFFFFF_i64] [also: vNum = 0x7FFFFFFFFFFFFFFFi64] [also: vNum: Int64 = 0x7FFFFFFFFFFFFFFF] Excel: ___ [MAJOR WARNING: Excel rounds numbers to 15 significant figures as they're typed, workaround: store as strings] Excel VBA: ___ [can use: vNum = CDec("&H7FFFFFFFFFFFFFFF")] [note: the Dec type has range +/- 79,228,162,514,264,337,593,543,950,335] [also (on 64-bit platforms): CLngLng()] Go: var vNum int64 = math.MaxInt64 [also: var vNum int64 = 0x7FFFFFFFFFFFFFFF] Java: Long vNum = Long.MAX_VALUE [also: Long vNum = 0x7FFFFFFFFFFFFFFFL] [WARNING: Java's Long is a signed Int64 (a Long is often a signed Int32)] JavaScript: ___ [can use: BigInt: vNum = 0x7FFFFFFFFFFFFFFFn] Kotlin: var vNum = Long.MAX_VALUE [also: var vNum = 0x7FFFFFFFFFFFFFFFL] PHP: ___ [can use (depends on PHP_INT_MAX): $vNum = 0x7FFFFFFFFFFFFFFF] [can use (BCMath functions): e.g. $vNum = bcadd("9223372036854775807", "0")] [also: $vNum = gmp_init("0x7FFFFFFFFFFFFFFF")] Python: ___ [can use: vNum: int = 0x7FFFFFFFFFFFFFFF] [note: 'Integers have unlimited precision.'] R: ___ [note: R uses signed Int32, e.g. .Machine$integer.max, e.g. as.integer(0x7FFFFFFF)] Ruby: ___ [can use: vNum = 0x7FFFFFFFFFFFFFFF] [note (bitwise-not): 'As integers are conceptually of infinite length, the result acts as if it had an infinite number of one bits to the left.'] Rust: let mut vNum = i64::MAX [let mut vNum: i64 = 0x7FFFFFFFFFFFFFFF] Scala: var vNum = Long.MaxValue [also: var vNum = 0x7FFFFFFFFFFFFFFFL] SQL (MySQL): ___ [can use (bigint): 9223372036854775807] [also (bigint unsigned): 0x7FFFFFFFFFFFFFFF+0] [also: CAST(1e100 AS SIGNED)] SQL (PostgreSQL): ___ [can use (bigint): 9223372036854775807] SQL (SQLite): ___ [can use: 0x7FFFFFFFFFFFFFFF] [also: CAST(1e999 AS INTEGER)] Swift: var vNum = Int64.max [also: var vNum: Int64 = 0x7FFFFFFFFFFFFFFF] UFL: Int64Min [or MinInt64/IntMin64][create min signed Int64, -0x8000000000000000 = -9223372036854775808][note: if Int64 is unavailable, Float64 is effectively 'Int53'] AutoHotkey: vNum := -0x8000000000000000 [note: AutoHotkey's Integer type is signed Int64] C++: auto vNum = std::numeric_limits<long long>::min() [requires (numeric_limits): #include <limits>] [also: long long vNum = -0x8000000000000000] [also: long long vNum = (~(unsigned long long)0 >> 1) + 1] C#: Int64 vNum = Int64.MinValue [also: Int64 vNum = -0x8000000000000000] Crystal: vNum = Int64::MIN [also: vNum = -0x8000000000000000_i64] [also: vNum = -0x8000000000000000i64] [also: vNum: Int64 = -0x8000000000000000] Excel: ___ [MAJOR WARNING: Excel rounds numbers to 15 significant figures as they're typed, workaround: store as strings] Excel VBA: ___ [can use: vNum = CDec("&H8000000000000000")] [note: the Dec type has range +/- 79,228,162,514,264,337,593,543,950,335] [also (on 64-bit platforms): CLngLng()] Go: var vNum int64 = math.MinInt64 [also: var vNum int64 = -0x8000000000000000] Java: Long vNum = Long.MIN_VALUE [also: Long vNum = -0x8000000000000000L] [WARNING: Java's Long is a signed Int64 (a Long is often a signed Int32)] JavaScript: ___ [can use: BigInt: vNum = -0x8000000000000000n] Kotlin: var vNum = Long.MIN_VALUE [also: var vNum: Long = -0x7FFFFFFFFFFFFFFFL - 0x1L] [note: invalid: var vNum: Long = -0x8000000000000000L] PHP: ___ [can use (depends on PHP_INT_MIN): $vNum = -0x7FFFFFFFFFFFFFFF - 0x1] [WARNING: -0x8000000000000000 returns a float, not an int] [can use (BCMath functions): e.g. $vNum = bcadd("-9223372036854775808", "0")] [also: $vNum = gmp_init("-0x8000000000000000")] Python: ___ [can use: vNum: int = -0x8000000000000000] [note: 'Integers have unlimited precision.'] R: ___ [note: R uses signed Int32, there is .Machine$integer.max, but no '.Machine$integer.min'] [WARNING: as.integer(-0x80000000) is invalid] Ruby: ___ [can use: vNum = -0x8000000000000000] [note (bitwise-not): 'As integers are conceptually of infinite length, the result acts as if it had an infinite number of one bits to the left.'] Rust: let mut vNum = i64::MIN [let mut vNum: i64 = -0x8000000000000000] Scala: var vNum = Long.MinValue [also: var vNum = -0x8000000000000000L] SQL (MySQL): ___ [can use (bigint): -9223372036854775808] [WARNING (creates a double, loses accuracy): -0x8000000000000000+0] [also: -CAST(1e100 AS SIGNED) - 1] SQL (PostgreSQL): ___ [can use (bigint): -9223372036854775808] SQL (SQLite): ___ [can use: -0x7FFFFFFFFFFFFFFF - 1] [also: CAST(-1e999 AS INTEGER)] Swift: var vNum = Int64.min [also: var vNum: Int64 = -0x8000000000000000] UFL: UInt64Max [or MaxUInt64/UIntMax64][create max unsigned Int64, 0xFFFFFFFFFFFFFFFF = 18446744073709551615][note: if UInt64 is unavailable, Int64 can be used as UInt64][note: if UInt64/Int64 are unavailable, Float64 can be used as 'Int53'] AutoHotkey: ___ [can use: vNum := Format("{:u}", -1)] [note: AHK uses signed Int64, these can be treated as UInt64, and displayed as UInt64, e.g. Format("{:u}", vNum)] C++: auto vNum = std::numeric_limits<unsigned long long>::max() [requires (numeric_limits): #include <limits>] [also: unsigned long long vNum = 0xFFFFFFFFFFFFFFFF] C#: UInt64 vNum = UInt64.MaxValue [also: UInt64 vNum = 0xFFFFFFFFFFFFFFFF] [also: unsigned long long vNum = ~0] Crystal: vNum = UInt64::MAX [also: vNum = 0xFFFFFFFFFFFFFFFF_u64] [also: vNum = 0xFFFFFFFFFFFFFFFFu64] [also: vNum: UInt64 = 0xFFFFFFFFFFFFFFFF] Excel: ___ [MAJOR WARNING: Excel rounds numbers to 15 significant figures as they're typed, workaround: store as strings] Excel VBA: ___ [can use: vNum = CDec("18446744073709551615")] [note: the Dec type has range +/- 79,228,162,514,264,337,593,543,950,335] [also (on 64-bit platforms): CLngLng()] Go: var vNum uint64 = math.MaxUint64 [also: var vNum uint64 = 0xFFFFFFFFFFFFFFFF] Java: ___ [can use: var vNum = new BigInteger("18446744073709551615")] [note: can store a UInt64 as an Int64 e.g.: var vNum = Long.parseUnsignedLong("18446744073709551615")] [note: the Long class provides: compareUnsigned/divideUnsigned/parseUnsignedLong/remainderUnsigned/toUnsignedString] [requires (BigInteger): import java.math.BigInteger] JavaScript: ___ [can use: BigInt: vNum = 0xFFFFFFFFFFFFFFFFn] Kotlin: var vNum = ULong.MAX_VALUE [also: var vNum = 0xFFFFFFFFFFFFFFFFuL] PHP: ___ [can use: $vNum = sprintf("%u", -1)] [can use (BCMath functions): e.g. $vNum = bcadd("18446744073709551615", "0")] [also: $vNum = bcceil("18446744073709551615")] [also: $vNum = gmp_init("0xFFFFFFFFFFFFFFFF")] Python: ___ [can use: vNum: int = 0xFFFFFFFFFFFFFFFF] [note: 'Integers have unlimited precision.'] R: ___ [note: R uses signed Int32, e.g. .Machine$integer.max, e.g. as.integer(0x7FFFFFFF)] Ruby: ___ [can use: vNum = 0xFFFFFFFFFFFFFFFF] [note (bitwise-not): 'As integers are conceptually of infinite length, the result acts as if it had an infinite number of one bits to the left.'] Rust: let mut vNum = u64::MAX [let mut vNum: u64 = 0xFFFFFFFFFFFFFFFF] Scala: ___ [can use: var vNum = BigInt("18446744073709551615")] [note: can store a UInt64 as an Int64 e.g. BigInt's toLong does overflow: var vNum = BigInt("18446744073709551615").toLong] SQL (MySQL): ___ [can use (bigint unsigned): 0xFFFFFFFFFFFFFFFF+0] [also (bigint unsigned): 18446744073709551615] SQL (PostgreSQL): ___ [can use (type: numeric): 18446744073709551615] SQL (SQLite): ___ Swift: var vNum = UInt64.max [also: var vNum: UInt64 = 0xFFFFFFFFFFFFFFFF] UFL: True/False [a Boolean value indicating that something is 'true' or 'false'][see also: IsTruthy/OpTern/OpShortTern/OpNotNotIntDemo/Array.NewAnyFalsyDemo] AutoHotkey: true/false [type: Integer] [note: case-insensitive (e.g. True/TRUE also work)] [note: true/false are equal to 1/0 respectively] C++: true/false [type: b] [note: true/false are equal to 1/0 respectively] C#: true/false [type: Boolean] [WARNING: true/false printed as 'True'/'False'] 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 (e.g. True/TRUE also work)] Python: True/False [type: bool] R: TRUE/FALSE [type: logical] [also: T/F] Ruby: true/false [type: TrueClass/FalseClass] Rust: true/false [type: bool] Scala: true/false [type: boolean] SQL (MySQL): true/false [type: int unsigned] [note: case-insensitive (e.g. True/TRUE also work)] [note: true/false are equal to 1/0 respectively] SQL (PostgreSQL): true/false [type: boolean] [note: case-insensitive (e.g. True/TRUE also work)] [note: true/false are often printed as t/f respectively] SQL (SQLite): true/false [type: integer] [note: case-insensitive (e.g. True/TRUE also work)] [note: true/false are equal to 1/0 respectively] Swift: true/false [type: Bool] UFL: IsTruthy [or IsTrue][demonstrate built-in functionality for checking a value's truthiness, or write custom code that checks for typically falsy values][inverse: IsFalsy/IsFalse][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 arrays/maps/objects, some objects types][see also: OpTern/OpShortTern/OpNotNotIntDemo/Array.NewAnyFalsyDemo/Any.TypeDefaultValueDemo] AutoHotkey: vIsTruthy := !!vVar [also: vVar ? true : false] [note (both): NaN considered truthy, "0" considered falsy] C++: vIsTruthy = !!vVar [also: vVar ? true : false] [WARNING (both): "" (char array) considered truthy] [WARNING (both): throw on std::string] [note (both): NaN/"0" considered truthy] C#: vIsTruthy = !((object[])["", 0, 0.0, false]).Contains(vVar) [note: works on negative zero too] [note (custom code): NaN/"0" considered truthy] Crystal: vIsTruthy = !["", 0, false].includes?(vVar) [note: works on floats too] [note (custom code): NaN/"0" considered truthy] [MAJOR WARNING: in Crystal, only false/nil 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 (custom code): NaN/"0" considered falsy] [note (where vNaN contains a NaN): (vNaN = 0) returns Empty] [note: ("0" = 0) returns True] Go: vIsTruthy := !slices.Contains[[]any, any]([]interface{}{"", 0, 0.0, false}, vVar) [note: works on negative zero too] [note (custom code): NaN/"0" considered truthy] Java: vIsTruthy = !List.of("", 0, 0.0, -0.0, false).contains(vVar) [note (custom code): NaN/"0" 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: Boolean(vVar)] [also: vVar ? true : false] [note (all): NaN considered falsy, "0" considered truthy] [WARNING: ("0" == 0) returns true, but (!!"0" == !!0) returns false] Kotlin: vIsTruthy = !arrayOf("", 0, 0.0, -0.0, false).contains(vVar) [note (custom code): NaN/"0" considered truthy] PHP: $vIsTruthy = !!$vVar [also: $vVar ? true : false] [note (both): NaN considered truthy, "0" considered falsy] [note: ("0" == 0) returns true] [MAJOR WARNING: [] (an empty array/map) is considered falsy] [note: new stdClass() is considered truthy] Python: vIsTruthy = not not vVar [also: vIsTruthy = True if vVar else False] [note: NaN/"0" considered truthy] [MAJOR WARNING: [] (an empty list) is considered falsy] [note: SimpleNamespace() is considered truthy] [note: {} (an empty dictionary) can't be checked for truthiness, because 'not not {}' throws] 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 (custom code): NaN considered truthy, "0" considered falsy] [note: ("0" == 0) returns TRUE] Ruby: vIsTruthy = !["", 0, false].include?(vVar) [note: works on floats too] [note (custom code): NaN/"0" considered truthy] [MAJOR WARNING: in Ruby, only false/nil considered falsy (e.g. 0 and "" are considered truthy)] Rust: ___ Scala: vIsTruthy = !Array("", 0, 0.0, -0.0, false).contains(vVar) [note (custom code): NaN/"0" considered truthy] SQL (MySQL): ___ [can use: (MyCol = 0)] [e.g. UPDATE MyTable SET v=(v=0) WHERE k='MyKey'] SQL (PostgreSQL): ___ [can use: (MyCol = 0)] [e.g. UPDATE MyTable SET v=(v=0) WHERE k='MyKey'] SQL (SQLite): ___ [can use: (MyCol == 0)] [e.g. UPDATE MyTable SET v=(v==0) WHERE k='MyKey'] 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 (custom code): NaN/"0" 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] SQL (MySQL): ___ [can use: if(MyCol, 'true', 'false')] SQL (PostgreSQL): ___ [can use: MyCol::text] [note: returns 'true'/'false'] [also: CAST(MyCol AS text)] SQL (SQLite): ___ [can use: iif(MyCol, 'true', 'false')] 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 !== "")] [also: Boolean(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 != "")] SQL (MySQL): ___ [can use: (MyCol != '')] SQL (PostgreSQL): ___ [can use: (MyCol != '')] SQL (SQLite): ___ [can use: (MyCol != '')] 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") SQL (MySQL): ___ [can use: (lower(MyCol) = 'true')] SQL (PostgreSQL): ___ [can use: (lower(MyCol) = 'true')] SQL (SQLite): ___ [can use: (lower(MyCol) == 'true')] Swift: vBool = (vText.lowercased() == "true") UFL: Abs [absolute value] AutoHotkey: Abs [e.g. Abs(vNum)] C++: abs [e.g. abs(vNum)] [also: labs(vNum)] [also: fabs(vNum)] [WARNING: labs() truncates floats] C#: Math.Abs [e.g. Math.Abs(vNum)] Crystal: abs [e.g. vNum.abs] Excel: ABS [e.g. ABS(A1)] Excel VBA: Abs [e.g. Abs(vNum)] Go: math.Abs [e.g. math.Abs(vNum)] Java: Math.abs [e.g. Math.abs(vNum)] JavaScript: Math.abs [e.g. Math.abs(vNum)] Kotlin: Math.abs [e.g. Math.abs(vNum)] PHP: abs [e.g. abs(vNum)] Python: abs [e.g. abs(vNum)] [also: math.fabs(vNum)] R: abs [e.g. abs(vNum)] Ruby: abs [e.g. vNum.abs] Rust: abs [e.g. vNum.abs()] Scala: math.abs [e.g. math.abs(vNum)] SQL (MySQL): abs [e.g. abs(MyCol)] SQL (PostgreSQL): abs [e.g. abs(MyCol)] [also: @ MyCol] SQL (SQLite): abs [e.g. abs(MyCol)] Swift: abs [e.g. abs(vNum)] [also: fabs(vNum)] [requires (fabs): import Foundation] UFL: Sign [or Signum][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: ___ [can use (ints/floats): cmp.Compare(vNum, 0)] 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 (floats): vSign = Math.signum(vNum)] 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/floats): (vNum).signum()] [MAJOR WARNING: for floats, signum() returns 1 or -1, not 0] Scala: math.signum [e.g. vSign = math.signum(vNum)] SQL (MySQL): sign [e.g. sign(MyCol)] SQL (PostgreSQL): sign [e.g. sign(MyCol)] SQL (SQLite): sign [e.g. sign(MyCol)] Swift: signum [e.g. (ints): 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)] SQL (MySQL): ___ [can use (-1**signbit) (NOT WORKING): pow(-1, (MyCol < 0) OR (MyCol = 0) AND (atan2(0, MyCol) != 0))] [WARNING: atan2(0,-0.0) returning 0 not pi] SQL (PostgreSQL): ___ [can use (-1**signbit) (NOT WORKING): pow(-1, CAST((MyCol < 0) OR (MyCol = 0) AND (atan2(0, MyCol) != 0) AS integer))] [WARNING: atan2(0,-0.0) returning 0 not pi] SQL (SQLite): ___ [can use (-1**signbit): pow(-1, (MyCol < 0) OR (MyCol == 0) AND (atan2(0, MyCol) != 0))] 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] SQL (MySQL): ___ [can use (is <0 or -0) (NOT WORKING): (MyCol < 0) OR (MyCol = 0) AND (atan2(0, MyCol) != 0)] [WARNING: atan2(0,-0.0) returning 0 not pi] SQL (PostgreSQL): ___ [can use (is <0 or -0) (NOT WORKING): CAST((MyCol < 0) OR (MyCol = 0) AND (atan2(0, MyCol) != 0) AS integer)] [WARNING: atan2(0,-0.0) returning 0 not pi] SQL (SQLite): ___ [can use (is <0 or -0): (MyCol < 0) OR (MyCol == 0) AND (atan2(0, MyCol) != 0)] Swift: ___ [can use: vSignBit = (copysign(1.0, vNum) > 0) ? 0 : 1] [requires (copysign): import Foundation] UFL: Pow [power (exponent)] AutoHotkey: ___ [can use: **] [e.g. vNum1 ** vNum2] C++: pow [e.g. pow(vNum1, vNum2)] C#: Math.Pow [e.g. Math.Pow(vNum1, vNum2)] Crystal: ___ [can use: **] [e.g. vNum1 ** vNum2] Excel: POWER [can use: ^] [e.g. POWER(A1,B1)] [WARNING: ^ is often used as bitwise-xor] Excel VBA: WorksheetFunction.Power [can use: ^] [e.g. WorksheetFunction.Power(vNum1, vNum2)] [WARNING: ^ is often used as bitwise-xor] Go: math.Pow [e.g. math.Pow(vNum1, vNum2)] [requires: import "math"] Java: Math.pow [e.g. Math.pow(vNum1, vNum2)] JavaScript: Math.pow [can use: **] [e.g. Math.pow(vNum1, vNum2)] Kotlin: Math.pow [e.g. Math.pow(vNum1, vNum2)] PHP: pow [can use: **] [e.g. pow(vNum1, vNum2)] Python: pow [also: math.pow/operator.pow] [can use: **] [e.g. pow(vNum1, vNum2)] [WARNING: math.pow always returns a float, whereas pow/operator.pow/** return an int if passed ints] R: ___ [can use: **] [also: ^] [e.g. vNum1 ** vNum2] Ruby: ___ [can use: **] [e.g. vNum1 ** vNum2] Rust: pow [also: powi/powf] [e.g. vNum1.pow(vNum2)] Scala: math.pow [e.g. math.pow(vNum1, vNum2)] SQL (MySQL): pow [e.g. pow(MyNum1, MyNum2)] [also: power()] SQL (PostgreSQL): pow [e.g. pow(MyNum1, MyNum2)] [also: power()] [also: ^] SQL (SQLite): pow [e.g. pow(MyNum1, MyNum2)] [also: power()] Swift: pow [e.g. pow(vNum1, vNum2)] [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 SQL (MySQL): sqrt/___ [can use (cbrt): pow(MyCol, 1/3.0)] [also (cbrt): pow(MyCol, 1/3)] SQL (PostgreSQL): sqrt/cbrt [also (square root): |/ MyCol] [also (cube root): ||/ MyCol] SQL (SQLite): sqrt/___ [can use (cbrt): pow(MyCol, 1/3.0)] Swift: sqrt/cbrt [also: squareRoot] UFL: Round [round to the nearest integer][tiebreak: round away from zero ('glass is half full' rather than 'half empty')][e.g. 0.5 rounds to 1, -0.5 rounds to -1, 2.5 rounds to 3][see also: RoundDP/RoundEven/Format/PrintShowMoreDigits] AutoHotkey: Round [e.g. vInt := Round(vNum)] C++: round [e.g. vFloat = round(vNum)] C#: ___ [can use: vFloat = Math.Round(vNum, MidpointRounding.AwayFromZero)] [WARNING: Math.Round uses bankers' rounding, if MidpointRounding omitted] Crystal: ___ [can use: vFloat = vNum.round(:TIES_AWAY)] [WARNING: round uses bankers' rounding, if RoundingMode omitted] Excel: ROUND [e.g. ROUND(A1,0)] Excel VBA: Round [e.g. vFloat = WorksheetFunction.Round(vNum, 0)] [WARNING: Round (not WorksheetFunction.Round) uses bankers' rounding, and doesn't handle negative DP] Go: math.Round [e.g. vFloat := math.Round(vNum)] Java: ___ [can use: Math.signum(vNum)*Math.round(Math.abs(vNum))] [WARNING: Math.round rounds towards +infinity in tiebreaks: e.g. 0.5 to 1, -0.5 to 0] [WARNING: Math.rint uses bankers' rounding] [also: toBigDecimal/String.format/DecimalFormat using RoundingMode.HALF_UP and/or Locale.ENGLISH] JavaScript: ___ [can use: vFloat = parseInt(vNum.toFixed())] [also: vFloat = Math.sign(vNum)*Math.round(Math.abs(vNum))] [WARNING: Math.round rounds towards +infinity in tiebreaks: e.g. 0.5 to 1, -0.5 to 0] Kotlin: ___ [can use: Math.signum(vNum)*Math.round(Math.abs(vNum))] [WARNING: Math.round/vNum.roundToInt()/vNum.roundToLong() round towards +infinity in tiebreaks: e.g. 0.5 to 1, -0.5 to 0] [WARNING: Math.rint/kotlin.math.round use bankers' rounding] [also: toBigDecimal/String.format/DecimalFormat using RoundingMode.HALF_UP and/or Locale.ENGLISH] [requires (roundToInt): import kotlin.math.roundToInt] [requires (roundToLong): import kotlin.math.roundToLong] PHP: round [e.g. $vFloat = round($vNum)] Python: ___ [can use: vInt = math.floor(vNum+0.5) if (vNum >= 0) else math.ceil(vNum-0.5)] [WARNING: round uses bankers' rounding] R: ___ [can use: vFloat = if (vNum >= 0) floor(vNum+0.5) else ceiling(vNum-0.5)] [also: vFloat = ifelse(vNum >= 0, floor(vNum+0.5), ceiling(vNum-0.5))] [WARNING: round uses bankers' rounding] [also (significant figures): signif] Ruby: round [e.g. vInt = vNum.round] Rust: round [e.g. vFloat = vNum.round()] Scala: ___ [can use: math.signum(vNum)*math.round(math.abs(vNum))] [WARNING: math.round rounds towards +infinity in tiebreaks: e.g. 0.5 to 1, -0.5 to 0] [WARNING: math.rint uses bankers' rounding] SQL (MySQL): round [e.g. round(MyCol)] [note: returns a float (type: decimal)] SQL (PostgreSQL): round [e.g. round(MyCol)] [note: returns a float (type: numeric)] SQL (SQLite): round [e.g. round(MyCol)] [note: returns a float] Swift: rounded [e.g. vFloat = vNum.rounded()] [also: vFloat = round(vNum)] [requires (round/rint/nearbyint): import Foundation] [WARNING: rint/nearbyint use bankers' rounding] UFL: RoundDP [round to n decimal places][e.g. 123.456 is 123.46 (2dp), and 100 ('-2dp')][functions handle 'negative' decimal places unless stated][see also: Round/Format] 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 rounds towards +infinity in tiebreaks: e.g. 0.5 to 1, -0.5 to 0] [WARNING: Math.rint uses bankers' rounding] [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] [also: vNum.toPrecision(vSigFig)] 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 rounds towards +infinity in tiebreaks: e.g. 0.5 to 1, -0.5 to 0] [WARNING: math.rint uses bankers' rounding] SQL (MySQL): round [e.g. round(MyCol, MyDP)] [note: returns a float (type: decimal)] [note: handles positive/0/negative/omitted DP] SQL (PostgreSQL): round [e.g. round(MyCol, MyDP)] [note: returns a float (type: numeric)] [note: handles positive/0/negative/omitted DP] SQL (SQLite): round [e.g. round(MyCol, MyDP)] [note: returns a float] [WARNING: negative DP: rounds to integer] [note: handles positive/0/omitted DP (and handles negative DP unintuitively)] Swift: ___ [e.g. vText = String(format:"%."+String(vDP)+"f", vNum)] [requires (format): import Foundation] [note: doesn't handle negative DP] UFL: RoundEven [or RoundToEven/RoundBankers][round to the nearest integer][tiebreak: round to the nearest even integer][e.g. -0.5 and 0.5 round to 0, 1.5 and 2.5 round to 2][bankers' rounding]['even.5' rounds towards 0 (to even), 'odd.5' rounds normally (away from 0) (to even)][see also: MRound] AutoHotkey: ___ [can use: vInt := (Mod(Abs(vNum),2)==0.5) ? Round(vNum-0.5*(vNum>=0?1:-1)) : Round(vNum)] C++: rint [e.g. vFloat = rint(vNum)] [also: vFloat = (fmod(abs(vNum),2)==0.5) ? (vNum-0.5*(vNum>=0?1:-1)) : round(vNum)] C#: Math.Round [e.g. vFloat = Math.Round(vNum)] Crystal: round [e.g. vFloat = vNum.round] Excel: ___ [can use: =IF(MOD(ABS(A1),2)=0.5,A1-0.5*SIGN(A1),ROUND(A1,0))] [also: =IF(MOD(ABS(A1),2)=0.5,MROUND(A1,SIGN(A1)*2),ROUND(A1,0))] Excel VBA: Round [e.g. vFloat = Round(vNum)] [also: IIf(vNum - 2 * Fix(Abs(vNum) / 2) = 0.5, vNum - 0.5 * Sgn(vNum), Round(vNum, 0))] [note: to calculate truncated mod: vRem = vNum1 - vNum2 * Fix(vNum1 / vNum2)] Go: math.RoundToEven [e.g. vFloat = math.RoundToEven(vNum)] Java: Math.rint [e.g. vFloat = Math.rint(vNum)] JavaScript: ___ [can use: vFloat = (Math.abs(vNum)%2==0.5) ? (vNum-0.5*Math.sign(vNum)) : parseInt(vNum.toFixed())] Kotlin: Math.rint [e.g. vFloat = Math.rint(vNum)] PHP: ___ [can use: $vFloat = (fmod(abs($vNum),2)==0.5) ? ($vNum-0.5*($vNum>=0?1:-1)) : round($vNum)] Python: round [e.g. vInt = round(vNum)] R: round [e.g. vFloat = round(vNum)] Ruby: ___ [can use: vInt = vNum.round(half: :even)] Rust: round_ties_even [e.g. vFloat = vNum.round_ties_even()] Scala: math.rint [e.g. vFloat = math.rint(vNum)] SQL (MySQL): ___ SQL (PostgreSQL): ___ SQL (SQLite): ___ Swift: rint [e.g. vFloat = rint(vNum)] [also: vFloat = nearbyint(vNum)] [requires (rint/nearbyint): import Foundation] UFL: Ceil [round up (towards +infinity)] AutoHotkey: Ceil [e.g. Ceil(vNum)] C++: ceil [e.g. ceil(vNum)] C#: Math.Ceiling [e.g. Math.Ceiling(vNum)] 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)] [note: CEILING.PRECISE (Excel 2010)] 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)] [note: CEILING.PRECISE (Excel 2010)] Go: math.Ceil [e.g. math.Ceil(vNum)] Java: Math.ceil [e.g. Math.ceil(vNum)] JavaScript: Math.ceil [e.g. Math.ceil(vNum)] Kotlin: Math.ceil [e.g. Math.ceil(vNum)] PHP: ceil [e.g. ceil($vNum)] Python: math.ceil [e.g. math.ceil(vNum)] R: ceiling [e.g. ceiling(vNum)] Ruby: ceil [e.g. vNum.ceil] Rust: ceil [e.g. vNum.ceil()] Scala: math.ceil [e.g. math.ceil(vNum)] SQL (MySQL): ceil [also: ceiling] SQL (PostgreSQL): ceil [also: ceiling] SQL (SQLite): ceil [also: ceiling] Swift: ceil [e.g. ceil(vNum)] [requires (ceil): import Foundation] UFL: Floor [round down (towards -infinity)] AutoHotkey: Floor [e.g. Floor(vNum)] C++: floor [e.g. floor(vNum)] C#: Math.Floor [e.g. Math.Floor(vNum)] Crystal: floor [e.g. vNum.floor] Excel: FLOOR.PRECISE [also: 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 FLOOR is unusual, it rounds towards 0 (it is usual to round towards -infinity)] [note: FLOOR.PRECISE (Excel 2010)] Excel VBA: WorksheetFunction.Floor_Precise [also: 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)] [note: FLOOR.PRECISE (Excel 2010)] Go: math.Floor [e.g. math.Floor(vNum)] Java: Math.floor [e.g. Math.floor(vNum)] JavaScript: Math.floor [e.g. Math.floor(vNum)] Kotlin: Math.floor [e.g. Math.floor(vNum)] PHP: floor [e.g. floor($vNum)] Python: math.floor [e.g. math.floor(vNum)] R: floor [e.g. floor(vNum)] Ruby: floor [e.g. vNum.floor] Rust: floor [e.g. vNum.floor()] Scala: math.floor [e.g. math.floor(vNum)] SQL (MySQL): floor SQL (PostgreSQL): floor SQL (SQLite): floor Swift: floor [e.g. floor(vNum)] [requires (floor): import Foundation] UFL: Trunc [truncate (round towards zero) (remove the fractional part)][see also: FloatToInt] AutoHotkey: Integer [e.g. Integer(vNum)] C++: trunc [e.g. trunc(vNum)] C#: Math.Truncate [e.g. Math.Truncate(vNum)] Crystal: to_i [e.g. vNum.to_i] Excel: TRUNC [e.g. TRUNC(A1)] [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 [e.g. Fix(vNum)] [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 [e.g. math.Trunc(vNum)] Java: int [e.g. (int)vNum] [also: Double.valueOf(vNum).intValue()] JavaScript: Math.trunc [e.g. Math.trunc(vNum)] Kotlin: kotlin.math.truncate [e.g. kotlin.math.truncate(vNum)] PHP: intval [e.g. intval($vNum)] Python: int [e.g. int(vNum)] [also: math.trunc(vNum)] [requires (trunc): import math] R: trunc [e.g. trunc(vNum)] [also: as.integer(vNum)] Ruby: truncate [e.g. vNum.truncate] [also: vNum.to_i] Rust: trunc [e.g. vNum.trunc()] Scala: toInt [e.g. vNum.toInt] [also: vNum.toInt.toDouble] SQL (MySQL): truncate [e.g. truncate(MyCol, 0)] [note: handles positive/0/negative DP] SQL (PostgreSQL): trunc [e.g. trunc(MyCol)] [also: trunc(MyCol, MyDP)] [note: handles positive/0/negative/omitted DP] SQL (SQLite): trunc [e.g. trunc(MyCol)] Swift: trunc [e.g. trunc(vNum)] [also: Int(vNum)] [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: Crystal'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] SQL (MySQL): ___ [can use: mod(MyCol, 1)] [also: MyCol % 1] SQL (PostgreSQL): ___ [can use: mod(MyCol, 1)] [also: MyCol % 1] SQL (SQLite): ___ [can use: mod(MyCol, 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 [e.g. Number(vNum)] C++: ___ C#: ___ Crystal: ___ Excel: N [e.g. N(A1)] Excel VBA: ___ Go: ___ Java: ___ JavaScript: Number [e.g. Number(vNum)] [note: this is really a ToFloat function, i.e. string to 64-bit float] Kotlin: ___ PHP: ___ Python: ___ R: as.numeric [e.g. as.numeric(vNum)] [note: this is really a ToFloat function, i.e. string to float] Ruby: ___ Rust: ___ Scala: ___ SQL (MySQL): ___ SQL (PostgreSQL): ___ SQL (SQLite): ___ 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)] [also: vNum = vText * 1] [also (unary plus): vNum = +vText] [WARNING: binary plus doesn't work, returns string: vNum = 0 + vText] [note (parseInt): 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] SQL (MySQL): CAST [e.g. (returns bigint): CAST(MyCol AS SIGNED)] [e.g. (returns bigint unsigned): CAST(MyCol AS UNSIGNED)] [note: returns 0 if fails] [note: accepts float-like input string] SQL (PostgreSQL): CAST [e.g. CAST(MyCol AS int)] [also: MyCol::int] [note: throws if fails] [WARNING: fails on float-like input string] SQL (SQLite): CAST [e.g. CAST(MyCol AS INTEGER)] [note: returns 0 if fails] [note: casts to real or int depending on whether the input looks float-like, and on the magnitude] 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 (how to handle non-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] [afterwards: vNum = isNaN(vNum) ? vDefault : vNum] 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] [afterwards (NA-coalescing): vNum = na.omit(c(vNum,vDefault))[1]] 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)] SQL (MySQL): ___ [can use: CAST(MyCol AS SIGNED)] [note: returns 0 if fails] SQL (PostgreSQL): ___ [can use: (CASE WHEN MyCol~E'^-?\\d+$' THEN MyCol::int ELSE 0 END)] [note: returns 0 if fails] [WARNING: ints that are beyond the range would still throw] SQL (SQLite): ___ [can use: CAST(MyCol AS INTEGER)] [note: returns 0 if fails] 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(vFloat)] 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] SQL (MySQL): CAST [e.g. CAST(MyCol AS SIGNED)] [note: if float beyond int64 range, returns max int64 if positive or throws if negative] SQL (PostgreSQL): CAST [e.g. CAST(MyCol AS int)] [note: if float beyond int64 range, throws] [also: MyCol::int] SQL (SQLite): CAST [e.g. CAST(MyCol AS INTEGER)] [note: if float beyond int64 range, returns max int64 or min int64] 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][see also: NaN/Infinity/NgvInfinity] 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)] [also: vNum = vText * 1] 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] SQL (MySQL): ___ [can use (returns a double): 0.0 + MyCol] [also (returns a double): MyCol + 0.0] [also: e.g. CAST(MyCol AS DECIMAL(6,3))] [note: returns 0.0 if fails] [MAJOR WARNING: CAST can reduce accuracy, e.g. CAST('123.456' AS DECIMAL) returns 123.0] SQL (PostgreSQL): CAST [e.g. CAST(MyCol AS float)] [also: MyCol::float] [note: throws if fails] SQL (SQLite): CAST [e.g. CAST(MyCol AS REAL)] [note: returns 0.0 if fails] 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] [afterwards: vNum = isNaN(vNum) ? vDefault : vNum] 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] [afterwards (NA-coalescing): vNum = na.omit(c(vNum,vDefault))[1]] 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)] SQL (MySQL): ___ [can use: 0.0 + MyCol] [can use: CAST(MyCol AS DECIMAL(6,3))] [note: returns 0.0 if fails] [note: some expressions print '0.0' as '0', e.g. SELECT 0.0 + '0.0'] SQL (PostgreSQL): ___ [can use: (CASE WHEN MyCol~E'^-?\\d+(\\.\\d+)?$' THEN MyCol::float ELSE 0.0 END)] [note: returns 0 if fails] [WARNING: some values would still throw] SQL (SQLite): ___ [can use: CAST(MyCol AS REAL)] [note: returns 0.0 if fails] [note: 'SELECT 0.0' prints '0' not '0.0'] 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] SQL (MySQL): ___ [can use (returns a decimal): MyCol + 0.0] [also: 0.0 + MyCol] SQL (PostgreSQL): CAST [e.g. CAST(MyCol AS float)] [also: MyCol + 0.0] [also: 0.0 + MyCol] SQL (SQLite): CAST [e.g. CAST(MyCol AS REAL)] [also: MyCol + 0.0] 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, b?1:0, map(false:0,true:1)[b]] AutoHotkey: Integer [note: no bool type: true = 1, false = 0] [e.g. vNum := Integer(vBool)] [also: vNum := vBool] [also: vNum := vBool + 0] [also: vNum := +vBool] [also: vNum := vBool ? 1 : 0] C++: int [note: no bool type: true = 1, false = 0] [e.g. vNum = (int)vBool] [also: vNum = vBool + 0] [also: vNum = +vBool] [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] [note: doesn't work: +A1] 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] [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] [also: $vNum = $vBool ? 1 : 0] Python: int [e.g. vNum = int(vBool)] [also: vNum = vBool + 0] [also: vNum = +vBool] R: ___ [can use: vNum = vBool + 0] [also: vNum = +vBool] [also: vNum = as.numeric(vBool)] [also: 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] SQL (MySQL): ___ [can use (returns an int): NOT NOT MyCol] [note: no bool type: true = 1, false = 0] SQL (PostgreSQL): ___ [can use: MyCol::int] [also: MyCol::int::bigint] SQL (SQLite): ___ [can use (returns an int): NOT NOT MyCol] [note: no bool type: true = 1, false = 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)] [also: MyCol <> 0] 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)] SQL (MySQL): ___ [can use (returns an int): NOT NOT MyCol] [also: MyCol != 0] [note: no bool type: true = 1, false = 0] SQL (PostgreSQL): ___ [can use: MyCol != 0] SQL (SQLite): ___ [can use (returns an int): NOT NOT MyCol] [also: MyCol != 0] [note: no bool type: true = 1, false = 0] Swift: ___ [can use: vBool = (vNum != 0)] UFL: LogNoBase [log(): whether it uses base e or base 10 (as the default base)][WARNING: bases 10 and e (e=2.7182818284...) are both common default bases][note: prefer functions with explicit names such as ln (base e) and log10 (base 10)] AutoHotkey: Log [e.g. Log(vNum)] [note: Log uses base 10] C++: log [e.g. log(vNum)] [note: log uses base e] C#: Math.Log [e.g. Math.Log(vNum)] [note: Math.Log uses base e] Crystal: Math.log [e.g. Math.log(vNum)] [note: Math.log uses base e] Excel: LOG [e.g. LOG(A1)] [note: LOG uses base 10] Excel VBA: Log [e.g. Log(vNum)] [note: Log uses base e] [also (uses base 10): WorksheetFunction.Log(vNum)] [WARNING: WorksheetFunction.Log uses base 10 if base omitted, Excel VBA's Log uses base e] Go: math.Log [e.g. math.Log(vNum)] [note: math.Log uses base e] Java: Math.log [e.g. Math.log(vNum)] [note: Math.log uses base e] JavaScript: Math.log [e.g. Math.log(vNum)] [note: Math.log uses base e] Kotlin: Math.log [e.g. Math.log(vNum)] [note: Math.log uses base e] [also: base must be specified: kotlin.math.log(vNum, vBase)] PHP: log [e.g. log(vNum)] [note: log uses base e] Python: math.log [e.g. math.log(vNum)] [note: math.log uses base e] R: log [e.g. log(vNum)] [note: log uses base e] Ruby: Math.log [e.g. Math.log(vNum)] [note: Math.log uses base e] Rust: ___ [can use: base must be specified: vNum.log(vBase)] Scala: math.log [e.g. math.log(vNum)] [note: math.log uses base e] SQL (MySQL): log [e.g. log(vNum)] [note: log uses base e] SQL (PostgreSQL): log [e.g. log(vNum)] [note: log uses base 10] SQL (SQLite): log [e.g. log(vNum)] [note: log uses base 10] Swift: log [e.g. log(vNum)] [note: log uses base e] [requires (log): import Foundation] [note: number must be a float] UFL: LogBase [log functions where a custom base can be specified][e.g. log2(x) = log10(x)/log10(2) = ln(x)/ln(2)] AutoHotkey: ___ [can use: Log(vNum)/Log(vBase)] [also: Ln(vNum)/Ln(vBase)] C++: ___ [can use: log10(vNum)/log10(vBase)] [also: log(vNum)/log(vBase)] [note: these are mathematically equivalent, but accuracy may vary, in testing, log10 gave slightly better approximations than log, most of the time: log2(vNum), log10(vNum)/log10(2), log(vNum)/log(2)] C#: Math.Log [e.g. Math.Log(vNum, vBase)] Crystal: Math.log [e.g. Math.log(vNum, vBase)] Excel: LOG [e.g. LOG(vNum, vBase)] Excel VBA: WorksheetFunction.Log [e.g. WorksheetFunction.Log(vNum, vBase)] Go: ___ [can use: math.Log10(vNum)/math.Log10(vBase)] [also: math.Log(vNum)/math.Log(vBase)] Java: ___ [can use: Math.log10(vNum)/Math.log10(vBase)] [also: Math.log(vNum)/Math.log(vBase)] JavaScript: ___ [can use: Math.log10(vNum)/Math.log10(vBase)] [also: Math.log(vNum)/Math.log(vBase)] Kotlin: kotlin.math.log [e.g. kotlin.math.log(vNum, vBase)] PHP: log [e.g. log(vNum, vBase)] Python: math.log [e.g. math.log(vNum, vBase)] R: log [e.g. log(vNum, vBase)] Ruby: Math.log [e.g. Math.log(vNum, vBase)] Rust: log [e.g. vNum.log(vBase)] Scala: ___ [can use: math.log10(vNum)/math.log10(vBase)] [also: math.log(vNum)/math.log(vBase)] SQL (MySQL): log [e.g. log(vBase, vNum)] [WARNING: param order differs: specify base: log(base, x), omit base: log(x)] [WARNING: param order: SQLite/PostgreSQL/MySQL use log(base, x), SQL Server uses log(x, base)] SQL (PostgreSQL): log [e.g. log(vBase, vNum)] [WARNING: param order differs: specify base: log(base, x), omit base: log(x)] [WARNING: param order: SQLite/PostgreSQL/MySQL use log(base, x), SQL Server uses log(x, base)] SQL (SQLite): log [e.g. log(vBase, vNum)] [WARNING: param order differs: specify base: log(base, x), omit base: log(x)] [WARNING: param order: SQLite/PostgreSQL/MySQL use log(base, x), SQL Server uses log(x, base)] Swift: ___ [can use: log10(vNum)/log10(vBase)] [also: log(vNum)/log(vBase)] [requires (log/log10): import Foundation] UFL: Ln/Log10/Log2 [log using base e/10/2][note: exp(ln(x)) = x][note: exp(ln(a)+ln(b)) = a*b][state if ln(0) doesn't return -infinity][note: ln(0) = -infinity] AutoHotkey: Ln/Log/___ C++: log/log10/log2 C#: Math.Log/Math.Log10/Math.Log2 Crystal: Math.log/Math.log10/Math.log2 Excel: LN/LOG10/___ [also: LOG: can specify base, default base 10] [note: LN(0) returns #NUM!] Excel VBA: Log/WorksheetFunction.Log10/___ [WARNING: WorksheetFunction.Log uses base 10 if base omitted, Excel VBA's Log uses base e] [note: Log(0) throws] 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 (ln/log10/log2 respectively): Math.log/Math.log10/Math.log2] PHP: log/log10/___ Python: math.log/math.log10/math.log2 [note: math.log(0) throws] R: log/log10/log2 Ruby: Math.log/Math.log10/Math.log2 Rust: ln/log10/log2 [also: log: must specify base] [e.g. (0f64).ln()] Scala: math.log/math.log10/___ SQL (MySQL): ln/log10/log2 [also: log: can specify base, default base e] [note: ln(0) returns NULL] SQL (PostgreSQL): ln/log10/log2 [also: log: can specify base, default base 10] [note: ln(0) throws] SQL (SQLite): ln/log10/log2 [also: log: can specify base, default base 10] [note: ln(0) returns NULL] 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 SQL (MySQL): exp SQL (PostgreSQL): exp SQL (SQLite): 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)] SQL (MySQL): ___ [can use: greatest(MyMin, least(MyCol, MyMax))] SQL (PostgreSQL): ___ [can use: greatest(MyMin, least(MyCol, MyMax))] SQL (SQLite): ___ [can use: max(MyMin, min(MyCol, MyMax))] 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: contains [e.g. (vMin..vMax).contains(vNum)] 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: ___ SQL (MySQL): ___ [can use (BETWEEN operator): (MyCol BETWEEN MyMin AND MyMax)] SQL (PostgreSQL): ___ [can use (BETWEEN operator): (MyCol BETWEEN MyMin AND MyMax)] SQL (SQLite): ___ [can use (BETWEEN operator): (MyCol BETWEEN MyMin AND MyMax)] 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: contains [e.g. (vMin..<vMax).contains(vNum)] PHP: ___ Python: ___ R: ___ Ruby: ___ [can use: (vMin...vMax) === vNum] [also: (vMin...vMax).cover?(vNum)] [also: (vMin...vMax).include?(vNum)] Rust: ___ Scala: ___ SQL (MySQL): ___ [can use: (MyMin <= MyCol AND MyCol < MyMax)] SQL (PostgreSQL): ___ [can use: (MyMin <= MyCol AND MyCol < MyMax)] SQL (SQLite): ___ [can use: (MyMin <= MyCol AND MyCol < MyMax)] 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) SQL (MySQL): ___ [can use: (MyMin <= MyCol AND MyCol <= MyMax)] SQL (PostgreSQL): ___ [can use: (MyMin <= MyCol AND MyCol <= MyMax)] SQL (SQLite): ___ [can use: (MyMin <= MyCol AND MyCol <= MyMax)] Swift: if (vMin <= vNum && vNum <= vMax) UFL: Mod [or TruncMod/IntMod][truncated modulo (C-style modulo) (output sign based on 1st param)][e.g. most languages use %][see also: TruncDiv/SymCharPct][WARNING: in some languages, % truncates or rounds operands before calculating: e.g. to test, use 10 % 3.5, i.e. 10 % 3.5 = 3, 10 % 3 = 1, 10 % 4 = 2] AutoHotkey: Mod [e.g. ints/floats: Mod(vNum1, vNum2)] C++: fmod [e.g. ints/floats: fmod(vNum1, vNum2)] [can use (ints only): %] C#: ___ [can use (ints/floats): %] Crystal: remainder [e.g. vNum1.remainder(vNum2)] Excel: ___ [can use: =A1-B1*QUOTIENT(A1,B1)] [also: =A1-B1*TRUNC(A1/B1)] [WARNING: Excel's MOD is a floor mod, Excel VBA's Mod operator is a truncated mod] Excel VBA: ___ [can use: vRem = vNum1 - vNum2 * (vNum1 \ vNum2)] [WARNING: backslash operator ('\') easily confused with slash operator ('/')] [also: vRem = vNum1 - vNum2 * Fix(vNum1 / vNum2)] [also (Mod operator, for safety use ints only): vNum1 Mod vNum2] [MAJOR WARNING: Mod operator rounds operands before calculating (note: Excel's sheet function MOD does not do this)] Go: math.Mod [e.g. ints/floats: math.Mod(vNum1, vNum2)] [can use (ints only): %] [also: math.Remainder] Java: ___ [can use (ints/floats): %] JavaScript: ___ [can use (ints/floats): %] Kotlin: ___ [can use (ints/floats): %] PHP: fmod [e.g. ints/floats: fmod($vNum1, $vNum2)] [can use (for safety use ints only): %] [MAJOR WARNING: % truncates operands before calculating] Python: math.fmod [e.g. math.fmod(vNum1, vNum2)] [can use: divmod (returns quotient and remainder as a tuple)] R: ___ [can use: vRem = vNum1 - vNum2*trunc(vNum1/vNum2)] Ruby: remainder [e.g. vNum1.remainder(vNum2)] Rust: ___ [can use (ints/floats): %] [also: checked_rem] [note: rem_euclid always returns positive/zero] Scala: ___ [can use (ints/floats): %] SQL (MySQL): mod [e.g. mod(MyCol1, MyCol2)] [also: MyCol1 % MyCol2] [also (MOD operator): MyCol1 MOD MyCol2] SQL (PostgreSQL): mod [e.g. mod(MyCol1, MyCol2)] [also: MyCol1 % MyCol2] SQL (SQLite): mod [e.g. mod(MyCol1, MyCol2)] [also (for safety use ints only): MyCol1 % MyCol2] [MAJOR WARNING: % truncates operands before calculating] Swift: truncatingRemainder [e.g. vNum1.truncatingRemainder(dividingBy:vNum2)] [can use (ints only): %] [also: fmod(vNum1, vNum2)] [requires (fmod): import Foundation] UFL: FloorMod [floor modulo (output sign based on 2nd param)][e.g. R uses %%][WARNING: Python uses %][e.g. trunc mod: -10 % 6 = -4][e.g. floor mod: -10 % 6 = 2][see also: FloorDiv] AutoHotkey: ___ [can use: vRem := vNum1 - vNum2*Floor(vNum1/vNum2)] C++: ___ [can use: vRem = vNum1 - vNum2*floor(vNum1/(double)vNum2)] C#: ___ [can use: vRem = vNum1 - vNum2*Math.Floor(vNum1/(double)vNum2)] Crystal: modulo [e.g. vNum1.modulo(vNum2)] [also (ints/floats): %] [WARNING (% and modulo): floor mod, not truncated mod] Excel: MOD [e.g. ints/floats: MOD(A1,B1)] [WARNING: Excel's MOD is a floor mod, Excel VBA's Mod operator is a truncated mod] Excel VBA: ___ [can use: vRem = vNum1 - vNum2 * Int(vNum1 / vNum2)] [WARNING: Excel VBA's Int function works like a floor function] Go: ___ [can use: vRem := float64(vNum1) - float64(vNum2)*math.Floor(float64(vNum1)/float64(vNum2))] Java: Math.floorMod [e.g. Math.floorMod(vNum1, vNum2)] JavaScript: ___ [can use: vRem = vNum1 - vNum2*Math.floor(vNum1/vNum2)] Kotlin: ___ [also: vRem = vNum1 - vNum2*Math.floor(vNum1/vNum2.toDouble())] PHP: ___ [can use: $vRem = $vNum1 - $vNum2*floor($vNum1/$vNum2)] Python: operator.mod [e.g. operator.mod(vNum1, vNum2)][also (ints/floats): %] [WARNING (% and mod): floor mod, not truncated mod] R: ___ [can use (ints/floats): vNum1 %% vNum2] Ruby: modulo [e.g. vNum1.modulo(vNum2)] [also (ints/floats): %] [WARNING (% and modulo): floor mod, not truncated mod] Rust: ___ [can use: vRem = (vNum1 as f64) - (vNum2 as f64)*(vNum1 as f64/vNum2 as f64).floor()] [note: rem_euclid always returns positive/zero] Scala: math.floorMod [e.g. Math.floorMod(vNum1, vNum2)] SQL (MySQL): ____ [can use: MyCol1 - MyCol2*floor(MyCol1/MyCol2)] [also (ints/floats, compatible with other SQL variants): MyCol1 - MyCol2*floor(1.0*MyCol1/MyCol2)] SQL (PostgreSQL): ____ [can use: MyCol1 - MyCol2*floor(1.0*MyCol1/MyCol2)] SQL (SQLite): ____ [can use: MyCol1 - MyCol2*floor(1.0*MyCol1/MyCol2)] Swift: ___ [can use: vRem = Double(vNum1) - Double(vNum2)*floor(Double(vNum1)/Double(vNum2))] [also (if both ints): vRem = vNum1 - vNum2*Int(floor(Double(vNum1)/Double(vNum2)))] [requires (floor): import Foundation] 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) SQL (MySQL): (MyCol1 % MyCol2 + MyCol2) % MyCol2 SQL (PostgreSQL): (MyCol1 % MyCol2 + MyCol2) % MyCol2 SQL (SQLite): (MyCol1 % MyCol2 + MyCol2) % MyCol2 Swift: (vNum1 % vNum2 + vNum2) % vNum2 UFL: TrueDiv [or Div/FloatDiv][true division, 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/TruncDiv/FloorDiv] AutoHotkey: ___ [can use: vNum1/vNum2] [WARNING (AHK v1): in some situations, vNum1 /= vNum2 does floor division, workaround: vNum1 := vNum1 / vNum2] C++: ___ [can use: vNum1/(double)vNum2] [WARNING: / on ints uses truncated division] C#: ___ [can use: vNum1/(double)vNum2] [WARNING: / on ints uses truncated 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 truncated division] JavaScript: ___ [can use: vNum1/vNum2] Kotlin: ___ [can use: vNum1/vNum2.toDouble()] [WARNING: / on ints uses truncated 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 truncated division] Scala: ___ [can use: vNum1/vNum2.toDouble] [WARNING: / on ints uses truncated division] SQL (MySQL): ___ [can use (ints/floats): MyCol1 / MyCol2] [also (ints/floats, compatible with other SQL variants): 1.0 * MyCol1 / MyCol2] SQL (PostgreSQL): ___ [can use (ints/floats): 1.0 * MyCol1 / MyCol2] [can use (floats only): MyCol1 / MyCol2] [WARNING (ints): / does truncated division] SQL (SQLite): ___ [can use (ints/floats): 1.0 * MyCol1 / MyCol2] [can use (floats only): MyCol1 / MyCol2] [WARNING (ints): / does truncated division] Swift: ___ [can use: vNum1/Double(vNum2)] [WARNING: / on ints uses truncated division] UFL: TruncDiv [or IntDiv][truncated division (C-style integer division)][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,A2)] [also: TRUNC(A1/A2)] Excel VBA: WorksheetFunction.Quotient [e.g. WorksheetFunction.Quotient(vNum1, vNum2)] [also: vNum1 \ vNum2] [also: Fix(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] SQL (MySQL): ___ [can use (ints/floats): MyCol1 DIV MyCol2] [can use (ints/floats): truncate(MyCol1 / MyCol2, 0)] [also (ints/floats, compatible with other SQL variants): truncate(1.0 * MyCol1 / MyCol2, 0)] SQL (PostgreSQL): div [e.g. div(MyCol1, MyCol2)] [also (ints/floats): trunc(1.0 * MyCol1 / MyCol2)] [WARNING (ints): / does truncated division] SQL (SQLite): ___ [can use (ints/floats): trunc(MyCol1 / MyCol2)] [can use (ints only): MyCol1 / MyCol2] [WARNING (ints): / does truncated division] Swift: ___ [can use: trunc(vNum1/vNum2)] [also (ints only): vNum1/vNum2] [requires (trunc): import Foundation] UFL: FloorDiv [floor division][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/B1)] [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)] SQL (MySQL): ___ [can use (ints/floats): floor(MyCol1 / MyCol2)] [also (ints/floats, compatible with other SQL variants): floor(1.0 * MyCol1 / MyCol2)] SQL (PostgreSQL): ___ [can use (ints/floats): floor(1.0 * MyCol1 / MyCol2)] [can use (floats only): floor(MyCol1 / MyCol2)] [WARNING (ints): / does truncated division] SQL (SQLite): ___ [can use (ints/floats): floor(1.0 * MyCol1 / MyCol2)] [can use (floats only): floor(MyCol1 / MyCol2)] [WARNING (ints): / does truncated division] Swift: ___ [can use: floor(Double(vNum1)/Double(vNum2))] [requires (floor): import Foundation] 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][e.g. hypot(3, 4) = 5][e.g. dist = hypot(x2-x1, y2-y1)] AutoHotkey: ___ [can use: Sqrt(vNum1**2+vNum2**2)] C++: hypot [e.g. hypot(vNum1, vNum2)] C#: Double.Hypot [e.g. Double.Hypot(vNum1, vNum2)] Crystal: Math.hypot [e.g. Math.hypot(vNum1, vNum2)] Excel: ___ [can use: SQRT(A1^2+B1^2)] Excel VBA: ___ [can use: Sqr(vNum1 ^ 2 + vNum2 ^ 2)] [note: 'Sqr', not 'Sqrt'] Go: math.Hypot [e.g. math.Hypot(vNum1, vNum2)] Java: Math.hypot [e.g. Math.hypot(vNum1, vNum2)] JavaScript: Math.hypot [e.g. Math.hypot(vNum1, vNum2)] [note: accepts more than 2 params] Kotlin: Math.hypot [e.g. Math.hypot(vNum1, vNum2)] PHP: hypot [e.g. hypot(vNum1, vNum2)] Python: math.hypot [e.g. math.hypot(vNum1, vNum2)] [note: accepts more than 2 params] R: ___ [can use: sqrt(vNum1**2+vNum2**2)] Ruby: Math.hypot [e.g. Math.hypot(vNum1, vNum2)] Rust: hypot [e.g. vNum1.hypot(vNum2)] Scala: math.hypot [e.g. math.hypot(vNum1, vNum2)] SQL (MySQL): ___ [can use: sqrt(pow(MyCol1,2)+pow(MyCol2,2))] SQL (PostgreSQL): ___ [can use: sqrt(pow(MyCol1,2)+pow(MyCol2,2))] SQL (SQLite): ___ [can use: sqrt(pow(MyCol1,2)+pow(MyCol2,2))] Swift: hypot [e.g. hypot(vNum1, vNum2)] [requires: import Foundation] 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: ___ SQL (MySQL): ___ SQL (PostgreSQL): factorial [e.g. factorial(MyCol)] [deprecated: MyCol !] [deprecated: !! MyCol] SQL (SQLite): ___ 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: ___ SQL (MySQL): ___ SQL (PostgreSQL): ___ SQL (SQLite): ___ Swift: ___ UFL: (Triang) [triangular number][see also: Range.ToArray/Array.Sum/Sum] AutoHotkey: ___ [can use: Integer(vNum*(vNum+1)/2)] C++: ___ C#: ___ Crystal: ___ Excel: ___ Excel VBA: ___ Go: ___ Java: ___ JavaScript: ___ Kotlin: ___ PHP: ___ Python: ___ R: ___ Ruby: ___ Rust: ___ Scala: ___ SQL (MySQL): ___ SQL (PostgreSQL): ___ SQL (SQLite): ___ Swift: ___ UFL: (Fib) [Fibonacci number] AutoHotkey: ___ C++: ___ C#: ___ Crystal: ___ Excel: ___ Excel VBA: ___ Go: ___ Java: ___ JavaScript: ___ Kotlin: ___ PHP: ___ Python: ___ R: ___ Ruby: ___ Rust: ___ Scala: ___ SQL (MySQL): ___ SQL (PostgreSQL): ___ SQL (SQLite): ___ 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 SQL (MySQL): radians/degrees SQL (PostgreSQL): radians/degrees SQL (SQLite): radians/degrees Swift: ___/___ UFL: Sin/Cos/Tan [e.g. in a right-angled triangle, 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 SQL (MySQL): sin/cos/tan SQL (PostgreSQL): sin/cos/tan SQL (SQLite): sin/cos/tan Swift: sin/cos/tan UFL: ASin/ACos/ATan [e.g. in a right-angled triangle, 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 SQL (MySQL): asin/acos/atan SQL (PostgreSQL): asin/acos/atan SQL (SQLite): asin/acos/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, atan2(0,0) = 0, atan2(y=0,x=-1) = pi] AutoHotkey: ATan2 [note: parameters: y, x] [also: DllCall("msvcrt\atan2", "Double",vNumY, "Double",vNumX, "Cdecl Double")] 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] SQL (MySQL): atan2 [note: parameters: y, x] [also: atan(y, x)] SQL (PostgreSQL): atan2 [note: parameters: y, x] SQL (SQLite): 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: ___/___/___/___/___/___/___ SQL (MySQL): ___/___/___/___/___/___/___ SQL (PostgreSQL): sind/cosd/tand/asind/acosd/atand/atan2d SQL (SQLite): ___/___/___/___/___/___/___ Swift: ___/___/___/___/___/___/___ UFL: DecToBase [integer to string][convert integer to string (in base n)][base convert][see also: DecToBin/DecToOct/DecToHex/FormatBinDemo/FormatHexDemo] AutoHotkey: ___ C++: ___ [WARNING: itoa (and _ui64tow) isn't built-in] [e.g. itoa(vNum, oBuffer, vBase)] 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: BASE (Excel 2013)] Excel VBA: WorksheetFunction.Base [e.g. WorksheetFunction(vNum, vBase)] [also (for dec2hex): Hex] [note: BASE (Excel 2013)] 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. vNum.toString(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] SQL (MySQL): conv [e.g. conv(MyCol, 10, MyBase)] [note: specify negative from_base, e.g. -10, for signed ints] SQL (PostgreSQL): ___ SQL (SQLite): ___ Swift: String [e.g. String(vNum, radix:vBase)] UFL: BaseToDec [string to integer][convert string (in base n) to integer][base convert][see also: BinToDec/OctToDec/HexToDec/HexPfxToDecUInt32Demo/HexPfxToDecUInt64Demo] AutoHotkey: ___ C++: std::stoi [e.g. vNum = std::stoi(vText, NULL, vBase)] [also: _wcstoi64/atoi/strtol] C#: Convert.ToInt32 [e.g. vNum = Convert.ToInt32(vText, vBase)] [WARNING: Convert.ToString/Convert.ToInt32 only handle bases 2/8/10/16] Crystal: to_i [e.g. vNum = vText.to_i(vBase)] Excel: DECIMAL [e.g. =DECIMAL(vText,vBase)] [note: DECIMAL (Excel 2013)] Excel VBA: WorksheetFunction.Decimal [e.g. vNum = WorksheetFunction.Decimal(vText, vBase)] [note: DECIMAL (Excel 2013)] Go: strconv.ParseInt [e.g. vNum, vErr := strconv.ParseInt(vText, vBase, 64)] [also: vNum, vErr := strconv.ParseUint(vText, vBase, 64)] [note: 64 to create an int64/uint64] Java: Integer.parseInt [e.g. vNum = Integer.parseInt(vText, vBase)] JavaScript: parseInt [e.g. vNum = parseInt(vText, vBase)] Kotlin: Integer.parseInt [e.g. vNum = Integer.parseInt(vText, vBase)] PHP: base_convert [e.g. $vNum = base_convert($vText, $vBase, 10)] Python: int [e.g. vNum = int(vText, vBase)] R: strtoi [e.g. vNum = strtoi(vText, vBase)] Ruby: to_i [e.g. vNum = vText.to_i(vBase)] Rust: from_str_radix [e.g. vNum = i32::from_str_radix(vText, vBase).unwrap()] Scala: Integer.parseInt [e.g. vNum = Integer.parseInt(vText, vBase)] SQL (MySQL): conv [e.g. conv(MyCol, MyBase, 10)] [note: specify negative from_base for signed ints] SQL (PostgreSQL): ___ SQL (SQLite): ___ Swift: strtol [e.g. vNum = strtol(vText, nil, vBase)] [requires (strtol/strtoul/strtoll/strtoull): import Foundation] [also: vNum = Int(vText, radix:vBase)!] UFL: (DecToBin) [convert integer to string (in base 2)][note: none of the examples below output a prefix, unless stated (e.g. '11111111' versus '0b11111111')][see also: FormatBinDemo] AutoHotkey: ___ [WARNING: not handled: Format("{:b}", vNum)] C++: ___ [can use: std::string vText = std::bitset<64>{vNum}.to_string()] [note: replace '64' to specify the number of bits] [requires (bitset): #include <bitset>] [also: std::format("{:b}", vNum)] [requires (format): #include <format>] [WARNING: itoa isn't built-in] C#: ___ [can use: Convert.ToString(vNum, 2)] [also: String.Format("{0:b}", vNum)] Crystal: to_s [e.g. vNum.to_s(2)] [also: sprintf("%b", vNum)] Excel: DEC2BIN [e.g. DEC2BIN(A1)] Excel VBA: WorksheetFunction.Dec2Bin [e.g. WorksheetFunction.Dec2Bin(vNum)] Go: strconv.FormatInt [e.g. strconv.FormatInt(int64(vNum), 2)] [also: strconv.FormatUint(uint64(vNum), 2)] [also: fmt.Sprintf("%b", vNum)] Java: Integer.toBinaryString [e.g. Integer.toBinaryString(vNum)] [WARNING: 'b' for bool, not bin: String.format("%b", vBool)] JavaScript: ___ [can use: vNum.toString(2)] Kotlin: Integer.toBinaryString [e.g. Integer.toBinaryString(vNum)] [WARNING: 'b' for bool, not bin: String.format("%b", vBool)] PHP: decbin [e.g. decbin($vNum)] [also: sprintf("%b", $vNum)] Python: bin [WARNING: bin() adds a 2-char prefix ('0b')] [e.g. bin(vNum)] [also: "{:b}".format(vNum)] R: ___ [can use: paste(as.integer(rev(intToBits(vNum))), collapse="")] [note (to remove leading zeros): sub("^0+(?=.)", "", vText, perl=TRUE)] [WARNING: not handled: sprintf("%b", vNum)] Ruby: to_s [e.g. vNum.to_s(2)] [also: sprintf("%b", vNum)] Rust: ___ [can use: format!("{:b}", vNum)] Scala: Integer.toBinaryString [e.g. Integer.toBinaryString(vNum)] [also: vNum.toBinaryString] [WARNING: 'b' for bool, not bin: String.format("%b", vBool)] SQL (MySQL): bin [e.g. bin(MyCol)] [also: conv(MyCol, 10, 2)] SQL (PostgreSQL): ___ [can use: MyCol::bit(64)] SQL (SQLite): ___ Swift: ___ [can use: String(vNum, radix:2)] [WARNING: not handled: String(format:"%x", vNum)] UFL: (BinToDec) [convert string (in base 2) to integer] AutoHotkey: ___ C++: ___ [can use: vNum = std::stoi(vBin, NULL, 2)] C#: ___ [can use: vNum = Convert.ToInt32(vBin, 2)] Crystal: to_i [e.g. vNum = vBin.to_i(2)] Excel: BIN2DEC [e.g. =BIN2DEC(A1)] Excel VBA: WorksheetFunction.Bin2Dec [e.g. vNum = WorksheetFunction.Bin2Dec(vBin)] Go: strconv.ParseInt [e.g. vNum, vErr := strconv.ParseInt(vBin, 2, 64)] [also: vNum, vErr := strconv.ParseUint(vBin, 2, 64)] Java: ___ [can use: vNum = Integer.parseInt(vBin, 2)] JavaScript: ___ [can use: vNum = parseInt(vBin, 2)] Kotlin: ___ [can use: vNum = Integer.parseInt(vBin, 2)] PHP: bindec [e.g. $vNum = bindec($vBin)] Python: ___ [can use: vNum = int(vBin, 2)] R: strtoi [e.g. vNum = strtoi(vBin, 2)] Ruby: to_i [e.g. vNum = vBin.to_i(2)] Rust: ___ [can use: vNum = i32::from_str_radix(vBin, 2).unwrap()] Scala: ___ [can use: vNum = Integer.parseInt(vBin, 2)] SQL (MySQL): conv [e.g. conv(MyBin, 2, 10)] SQL (PostgreSQL): ___ [can use: lpad(MyBin, 32, '0')::bit(32)::int] [MAJOR WARNING: lpad() can crop strings] SQL (SQLite): ___ Swift: strtol [e.g. vNum = strtol(vBin, nil, 2)] [requires (strtol/strtoul/strtoll/strtoull): import Foundation] [also: vNum = Int(vBin, radix:2)!] UFL: (DecToOct) [convert integer to string (in base 8)][note: none of the examples below output a prefix, unless stated (e.g. '377' versus '0o377')] AutoHotkey: ___ [can use: Format("{:o}", vNum)] C++: ___ [can use: std::stringstream oStream; oStream << std::oct << vNum; std::string vText = oStream.str();] [requires (stringstream): #include <sstream>] [WARNING: itoa isn't built-in] C#: ___ [can use: Convert.ToString(vNum, 8)] Crystal: to_s [e.g. vNum.to_s(8)] Excel: DEC2OCT [e.g. DEC2OCT(A1)] Excel VBA: Oct [e.g. Oct(vNum)] [also: WorksheetFunction.Dec2Oct(vNum)] Go: strconv.FormatInt [e.g. strconv.FormatInt(int64(vNum), 8)] [also: strconv.FormatUint(uint64(vNum), 8)] Java: Integer.toOctalString [e.g. Integer.toOctalString(vNum)] JavaScript: ___ [can use: vNum.toString(8)] Kotlin: Integer.toOctalString [e.g. Integer.toOctalString(vNum)] PHP: decoct [e.g. decoct($vNum)] Python: oct [WARNING: oct() adds a 2-char prefix ('0o')] [e.g. oct(vNum)] 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!("{:o}", vNum)] Scala: Integer.toOctalString [e.g. Integer.toOctalString(vNum)] [also: vNum.toOctalString] SQL (MySQL): oct [e.g. oct(MyCol)] [also: conv(MyCol, 10, 8)] SQL (PostgreSQL): ___ SQL (SQLite): ___ [can use: format('%o', 100)] [alias (deprecated): printf] Swift: ___ [can use: String(vNum, radix:8)] UFL: (OctToDec) [convert string (in base 8) to integer] AutoHotkey: ___ C++: ___ [can use: vNum = std::stoi(vOct, NULL, 8)] C#: ___ [can use: vNum = Convert.ToInt32(vOct, 8)] Crystal: to_i [e.g. vNum = vOct.to_i(8)] Excel: OCT2DEC [e.g. =OCT2DEC(A1)] Excel VBA: WorksheetFunction.Oct2Dec [e.g. vNum = WorksheetFunction.Oct2Dec(vOct)] [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. vNum, vErr := strconv.ParseInt(vOct, 8, 64)] [also: vNum, vErr := strconv.ParseUint(vOct, 8, 64)] Java: ___ [can use: vNum = Integer.parseInt(vOct, 8)] JavaScript: ___ [can use: vNum = parseInt(vOct, 8)] Kotlin: ___ [can use: vNum = Integer.parseInt(vOct, 8)] PHP: octdec [e.g. $vNum = octdec($vOct)] Python: ___ [can use: vNum = int(vOct, 8)] R: strtoi [e.g. vNum = strtoi(vOct, 8)] Ruby: to_i [e.g. vNum = vOct.to_i(8)] Rust: ___ [can use: vNum = i32::from_str_radix(vOct, 8).unwrap()] Scala: ___ [can use: vNum = Integer.parseInt(vOct, 8)] SQL (MySQL): conv [e.g. conv(MyOct, 8, 10)] SQL (PostgreSQL): ___ SQL (SQLite): ___ Swift: strtol [e.g. vNum = strtol(vOct, nil, 8)] [requires (strtol/strtoul/strtoll/strtoull): import Foundation] [also: vNum = Int(vOct, radix:8)!] UFL: (DecToHex) [convert integer to string (in base 16)][note: none of the examples below output a prefix, unless stated (e.g. 'ff' versus '0xff')][see also: FormatHexDemo] AutoHotkey: ___ [can use (lower case): Format("{:x}", vNum)] [also (upper case): Format("{:X}", vNum)] C++: ___ [can use: std::stringstream oStream; oStream << std::hex << vNum; std::string vText = oStream.str();] [requires (stringstream): #include <sstream>] [WARNING: itoa isn't built-in] C#: ___ [can use (lower case): Convert.ToString(vNum, 16)] Crystal: to_s [e.g. (lower case): vNum.to_s(16)] Excel: DEC2HEX [e.g. (upper case): DEC2HEX(A1)] Excel VBA: Hex [e.g. (upper case): Hex(vNum)] [also (upper case): WorksheetFunction.Dec2Hex(vNum)] Go: strconv.FormatInt [e.g. (lower case): strconv.FormatInt(int64(vNum), 16)] [also (lower case): strconv.FormatUint(uint64(vNum), 16)] Java: Integer.toHexString [e.g. (lower case): Integer.toHexString(vNum)] JavaScript: ___ [can use (lower case): vNum.toString(16)] Kotlin: Integer.toHexString [e.g. (lower case): Integer.toHexString(vNum)] [also (lower case): vNum.toHexString(HexFormat{number{removeLeadingZeros=true}})] [WARNING: Integer.toHexString / vNum.toHexString work differently] PHP: dechex [e.g. (lower case): dechex($vNum)] Python: hex [WARNING: hex() adds a 2-char prefix ('0x')] [e.g. (lower case): hex(vNum)] R: as.hexmode [e.g. as.character(as.hexmode(vNum))] [also: sprintf("%x", vNum)] Ruby: to_s [e.g. (lower case): vNum.to_s(16)] Rust: ___ [can use (lower case): format!("{:x}", vNum)] Scala: Integer.toHexString [e.g. (lower case): Integer.toHexString(vNum)] [also (lower case): vNum.toHexString] SQL (MySQL): hex [e.g. hex(MyCol)] [also: conv(MyCol, 10, 16)] SQL (PostgreSQL): to_hex [e.g. to_hex(MyCol)] SQL (SQLite): ___ [can use: format('%x', 100)] [alias (deprecated): printf] Swift: ___ [can use (lower case): String(vNum, radix:16)] UFL: (HexToDec) [convert string (in base 16) to integer][see also: HexPfxToDecUInt32Demo/HexPfxToDecUInt64Demo] AutoHotkey: ___ [can use: vNum := Integer("0x" vHex)] [also: vNum := Format("{:i}", "0x" vHex)] [also: vNum := Format("{:u}", "0x" vHex)] C++: ___ [can use: vNum = std::stoi(vHex, NULL, 16)] C#: ___ [can use: vNum = Convert.ToInt32(vHex, 16)] Crystal: to_i [e.g. vNum = vHex.to_i(16)] Excel: HEX2DEC [e.g. =HEX2DEC(A1)] Excel VBA: WorksheetFunction.Hex2Dec [e.g. vNum = WorksheetFunction.Hex2Dec(vHex)] [also: CDec (or CLngLng/CDbl/CLng/CInt/Val/Abs) with '&H' (not '0x') prefix, e.g. CDec("&HFF") equals 255] [MAJOR WARNING: '&H' is unpredictable in whether it returns a positive/negative result, and Val() gives unpredictable results in general, e.g. test '&HFFFF'/'&HFFFFFFFF' (e.g. try 4/8/9/13/16 F's)] Go: strconv.ParseInt [e.g. vNum, vErr := strconv.ParseInt(vHex, 16, 64)] [also: vNum, vErr := strconv.ParseUint(vHex, 16, 64)] Java: ___ [can use: vNum = Integer.parseInt(vHex, 16)] JavaScript: ___ [can use: vNum = parseInt(vHex, 16)] Kotlin: ___ [can use: vNum = Integer.parseInt(vHex, 16)] PHP: hexdec [e.g. $vNum = hexdec($vHex)] Python: ___ [can use: vNum = int(vHex, 16)] R: strtoi [e.g. vNum = strtoi(vHex, 16)] Ruby: to_i [e.g. vNum = vHex.to_i(16)] Rust: ___ [can use: vNum = i32::from_str_radix(vHex, 16).unwrap()] Scala: ___ [can use: vNum = Integer.parseInt(vHex, 16)] SQL (MySQL): conv [e.g. conv(MyHex, 16, 10)] [also (e.g. 0xF = 15): x'0f'+0] SQL (PostgreSQL): ___ [can use: ('0x'||MyHex)::float::numeric] [WARNING: casting to float could lose accuracy] SQL (SQLite): ___ Swift: strtol [e.g. vNum = strtol(vHex, nil, 16)] [requires (strtol/strtoul/strtoll/strtoull): import Foundation] [also: vNum = Int(vHex, radix:16)!] UFL: (HexPfxToDecUInt32Demo) [convert string '0xFFFFFFFF' to 4294967295 (as some form of int, else a string)][convert hex string with '0x' prefix to integer (dec) as UInt32][see also: HexToDec/Format/StrToInt/UInt64Max/SymPfxHex] AutoHotkey: vNum := Integer("0xFFFFFFFF") [also: vNum := Format("{:i}", "0xFFFFFFFF")] [also: vNum := Format("{:u}", "0xFFFFFFFF")] C++: vNum = std::stoul("0xFFFFFFFF", NULL, 0) C#: vNum = Convert.ToUInt32("0xFFFFFFFF", 16) Crystal: vNum = "0xFFFFFFFF".to_u32(prefix:true) Excel: =HEX2DEC(REPLACE("0xFFFFFFFF",1,2,"")) [note: REPLACE() is used to remove the '0x'] Excel VBA: vNum = WorksheetFunction.Hex2Dec(Mid("0xFFFFFFFF", 3)) Go: vNum, vErr := strconv.ParseInt("0xFFFFFFFF", 0, 32) [also: strconv.ParseUint()] Java: vNum = new BigInteger("0xFFFFFFFF".substring(2), 16) [can use (for Int32): vNum = Integer.parseInt("0x7FFFFFFF".substring(2), 16)] [also (for Int32): vNum = Integer.decode("0x7FFFFFFF")] [requires (BigInteger): import java.math.BigInteger] JavaScript: vNum = parseInt("0xFFFFFFFF") Kotlin: vNum = java.math.BigInteger("0xFFFFFFFF".substring(2), 16) [can use (for Int32): vNum = Integer.parseInt("0x7FFFFFFF".substring(2), 16)] [also (for Int32): vNum = Integer.decode("0x7FFFFFFF")] PHP: $vNum = hexdec("0xFFFFFFFF") Python: vNum = int("0xFFFFFFFF", 0) R: vNum = as.numeric("0xFFFFFFFF") [can use (for Int32): vNum = strtoi("0x7FFFFFFF")] Ruby: vNum = "0xFFFFFFFF".to_i(0) Rust: vNum = u32::from_str_radix("0xFFFFFFFF".trim_start_matches("0x"), 16).unwrap() Scala: vNum = BigInt("0xFFFFFFFF".substring(2), 16) [can use (for Int32): vNum = Integer.parseInt("0x7FFFFFFF".substring(2), 16)] [also (for Int32): vNum = Integer.decode("0x7FFFFFFF")] SQL (MySQL): conv(substr('0xFFFFFFFF', 3), 16, 10) SQL (PostgreSQL): '0xFFFFFFFF'::float::numeric [WARNING: casting to float could lose accuracy] SQL (SQLite): ___ Swift: vNum = strtoul("0xFFFFFFFF", nil, 0) [note: strtol() also works] [also: vNum = Int(String("0xFFFFFFFF".dropFirst(2)), radix:16)!] [requires (strtol/strtoul/strtoll/strtoull): import Foundation] UFL: (HexPfxToDecUInt64Demo) [convert string '0xFFFFFFFFFFFFFFFF' to 18446744073709551615 (as some form of int, else a string)][convert hex string with '0x' prefix to integer (dec) as UInt64][two key problems: handling '0x' and handling UInt64][see also: HexToDec/Format/StrToInt/UInt64Max/SymPfxHex] AutoHotkey: vNum := Format("{:u}", "0xFFFFFFFFFFFFFFFF") C++: vNum = std::stoull("0xFFFFFFFFFFFFFFFF", NULL, 0) C#: vNum = Convert.ToUInt64("0xFFFFFFFFFFFFFFFF", 16) Crystal: vNum = "0xFFFFFFFFFFFFFFFF".to_u64(prefix:true) Excel: ___ [can use (49 1 bits, exact): =HEX2DEC("1FFFF")*256^4+HEX2DEC("FFFFFFFF"), equals 562949953421311] [also (64 1 bits, approximate): =HEX2DEC("FFFFFFFF")*256^4+HEX2DEC("FFFFFFFF"), equals 18446744073709600000, which is off by 48385] [note: general formula for hex strings starting '0x': =HEX2DEC(IFERROR(MID(A1,3,LEN(A1)-10),0))*256^4+HEX2DEC(RIGHT(REPLACE(A1,1,2,""),8))] [WARNING: HEX2DEC() handles 10 chars max] [note: REPLACE() is used to remove the '0x'] Excel VBA: ___ [can use: vHex = "0xFFFFFFFFFFFFFFFF": vNum = CDec(WorksheetFunction.Hex2Dec("0" & Mid(vHex, 3, IIf(Len(vHex) > 10, Len(vHex) - 10, 0)))) * 256 ^ 4 + CDec(WorksheetFunction.Hex2Dec(Right(Mid(vHex, 3), 8)))] [WARNING: a solution based on CDec("&H" & Mid("0xFFFFFFFFFFFFFFFF", 3)) could be reasonably succinct, however '&H' is unpredictable in whether it returns a positive/negative result] Go: vNum, vErr := strconv.ParseUint("0xFFFFFFFFFFFFFFFF", 0, 64) Java: vNum = new BigInteger("0xFFFFFFFFFFFFFFFF".substring(2), 16) [requires (BigInteger): import java.math.BigInteger] JavaScript: vNum = BigInt("0xFFFFFFFFFFFFFFFF") Kotlin: vNum = java.math.BigInteger("0xFFFFFFFFFFFFFFFF".substring(2), 16) PHP: $vNum = gmp_strval(gmp_init("0xFFFFFFFFFFFFFFFF")) Python: vNum = int("0xFFFFFFFFFFFFFFFF", 0) R: ___ [can use (53 1 bits, exact): vNum = as.numeric("0x1FFFFFFFFFFFFF"), equals 9007199254740991] [also (64 1 bits, approximate): vNum = as.numeric("0xFFFFFFFFFFFFFFFF"), equals 18446744073709551616, which is off-by-one] Ruby: vNum = "0xFFFFFFFFFFFFFFFF".to_i(0) Rust: vNum = u64::from_str_radix("0xFFFFFFFFFFFFFFFF".trim_start_matches("0x"), 16).unwrap() Scala: vNum = BigInt("0xFFFFFFFFFFFFFFFF".substring(2), 16) SQL (MySQL): conv(substr('0xFFFFFFFFFFFFFFFF', 3), 16, 10) SQL (PostgreSQL): ___ [can use: (18446744073709551616 + ('x'||right('0000000000000000'||substr('0xFFFFFFFFFFFFFFFF',3),16))::bit(64)::bigint) % 18446744073709551616] [algorithm: e.g. 'xFF'::bit(64)::bigint is treated as 1 byte of data with 7 *trailing* null bytes (we use padding to add *leading* zeros if necessary, to ensure 8 bytes of data), it is converted to a string of 64 bits (1's/0's), then converted to a (signed) Int64, we use + and % to convert to an (unsigned) UInt64] [WARNING: 'xFF'::bit(64)::bigint returns 0xFF00000000000000 (as an Int64), 'x00000000000000FF'::bit(64)::bigint returns 0xFF] SQL (SQLite): ___ Swift: vNum = strtoull("0xFFFFFFFFFFFFFFFF", nil, 0) [note: strtoul() also works] [also: vNum = UInt64(String("0xFFFFFFFFFFFFFFFF".dropFirst(2)), radix:16)!] [requires (strtol/strtoul/strtoll/strtoull): import Foundation] UFL: Combin/CombinR [get count of: combinations without repetition, combinations with repetition] AutoHotkey: ___/___ C++: ___/___ C#: ___/___ Crystal: ___/___ Excel: COMBIN/COMBINA [note: COMBINA (Excel 2013)] Excel VBA: WorksheetFunction.Combin/___ Go: ___/___ Java: ___/___ JavaScript: ___/___ Kotlin: ___/___ PHP: ___/___ Python: math.comb/___ R: choose/___ Ruby: ___/___ Rust: ___/___ Scala: ___/___ SQL (MySQL): ___/___ SQL (PostgreSQL): ___/___ SQL (SQLite): ___/___ Swift: ___/___ UFL: Permut/PermutR [get count of: permutations without repetition, permutations with repetition] AutoHotkey: ___/___ C++: ___/___ C#: ___/___ Crystal: ___/___ Excel: PERMUT/PERMUTATIONA [note: PERMUTATIONA (Excel 2013)] Excel VBA: WorksheetFunction.Permut/___ Go: ___/___ Java: ___/___ JavaScript: ___/___ Kotlin: ___/___ PHP: ___/___ Python: math.perm/___ R: ___/___ Ruby: ___/___ Rust: ___/___ Scala: ___/___ SQL (MySQL): ___/___ SQL (PostgreSQL): ___/___ SQL (SQLite): ___/___ 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: ___ SQL (MySQL): ___ SQL (PostgreSQL): ___ SQL (SQLite): ___ 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: ___ SQL (MySQL): ___ SQL (PostgreSQL): ___ SQL (SQLite): ___ Swift: ___ UFL: NumCompare [note: can typically also use: < > ==][compares numbers and returns 1/0/-1 accordingly (or positive/0/negative)][WARNING: the sign(a-b) workaround can overflow, giving the wrong value][see also: Sign/StrCompare] AutoHotkey: ___ [can use: vCmp := (vNum1>vNum2)?1:(vNum1<vNum2)?-1:0] [can use (doesn't work in AHK v1): vCmp := (vNum1>vNum2)||-(vNum1<vNum2)] 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: cmp.Compare [e.g. cmp.Compare(vNum1, vNum2)] Java: Integer.compare [e.g. vCmp = Integer.compare(vNum1, vNum2)] [also: Double.compare] [also (works with Integer but not int): vNum1.compareTo(vNum2)] JavaScript: ___ [can use (< >): vCmp = +(vNum1>vNum2)||-(vNum1<vNum2)] [also: vCmp = (vNum1>vNum2)?1:(vNum1<vNum2)?-1:0] [also: vCmp = Math.sign(vNum1-vNum2)] Kotlin: compareValues [e.g. vCmp = compareValues(vNum1, vNum2)] [also: compareValuesBy] PHP: ___ [can use: <=>] [e.g. $vCmp = $vNum1 <=> $vNum2] Python: ___ [can use: vCmp = +(vNum1>vNum2) or -(vNum1<vNum2)] R: ___ [can use: vCmp = (if (vNum1<vNum2) -1 else +(vNum1>vNum2))] [also: 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] SQL (MySQL): ___ [can use: sign(MyCol1-MyCol2)] SQL (PostgreSQL): ___ [can use: sign(MyCol1-MyCol2)] SQL (SQLite): ___ [can use: sign(MyCol1-MyCol2)] Swift: ___ [can use: vCmp = (vNum1>vNum2) ? 1 : (vNum1<vNum2) ? -1 : 0] 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: ___ [WARNING: version.Compare has limited functionality] 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: ___ SQL (MySQL): ___ SQL (PostgreSQL): ___ SQL (SQLite): ___ Swift: ___ UFL: PopCount32/PopCount64 [or PopCnt/BitCount][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 SQL (MySQL): ___/bit_count [can use (pop count 32-bit): bit_count(MyCol&0xFFFFFFFF)] SQL (PostgreSQL): ___/___ SQL (SQLite): ___/___ Swift: ___/___ UFL: (BitAnd)/(BitOr)/(BitXor) [And/Or/Xor could potentially handle n params/an array][E.g. 6&5=4, 6|5=7, 6^5=3] AutoHotkey: ___/___/___ [can use: & | ^] C++: ___/___/___ [can use: & | ^] C#: ___/___/___ [can use: & | ^] Crystal: ___/___/___ [can use: & | ^] Excel: BITAND/BITOR/BITXOR [note: BITAND/BITOR/BITXOR (Excel 2013)] Excel VBA: WorksheetFunction.Bitand/WorksheetFunction.Bitor/WorksheetFunction.Bitxor [can use (operators): And Or Xor] [note: BITAND/BITOR/BITXOR (Excel 2013)] 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: & | ^] SQL (MySQL): ___/___/___ [can use: & | ^] [also (xor): (~(a&b))&(a|b)] [WARNING: XOR operator does logical XOR (not bitwise XOR), i.e. is exactly one value truthy] SQL (PostgreSQL): ___/___/___ [can use: & | #] [also (xor): (~(a&b))&(a|b)] [note: unusual operator symbol: #] SQL (SQLite): ___/___/___ [can use: & |] [can use (xor): (~(a&b))&(a|b)] [note (xor): (universal set - intersection(a,b)) & union(a,b) = union(a,b) - intersection(a,b)] Swift: ___/___/___ [can use: & | ^] UFL: (BitNot) [workaround: 'xor' with -1 (i.e. all 1 bits)][E.g. ~10 = -11, ~-10 = 9][note: if working with (signed) Int64: xor with -1 (Int64 result), then and with 0xFFFFFFFF (for UInt32), then << 32 >> 32 (for signed Int32)] AutoHotkey: ___ [can use: ~] [WARNING: AHK v1: ~ works as 64-bit/32-bit depending on the input] [note: works consistently in AHK v1/v2: vNum ^ -1] 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: ~] SQL (MySQL): ___ [can use: ~] SQL (PostgreSQL): ___ [can use: ~] SQL (SQLite): ___ [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: BITLSHIFT (Excel 2013)] Excel VBA: WorksheetFunction.Bitlshift [note: added in Excel 2013] [can use (operators): And Or * / ^ (note: And and Or are bitwise for integer operands)] [note: BITLSHIFT (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: <<] SQL (MySQL): ___ [can use: <<] SQL (PostgreSQL): ___ [can use: <<] SQL (SQLite): ___ [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][typically, for >>: one-fill if first bit is 1 and type is signed, else zero-fill][typically, for >>>: zero-fill] AutoHotkey: ___/___ [can use: >> >>>] C++: ___/___ [can use: >>] C#: ___/___ [can use: >> >>>] Crystal: ___/___ [can use: >>] Excel: BITRSHIFT/___ [note: BITRSHIFT (Excel 2013)] Excel VBA: WorksheetFunction.Bitrshift/___ [note: added in Excel 2013] [can use (operators): And Or * / ^ (note: And and Or are bitwise for integer operands)] [note: BITRSHIFT (Excel 2013)] Go: ___/___ [can use: >>] Java: ___/___ [can use: >> >>>] JavaScript: ___/___ [can use: >> >>>] [note: can't use >>> with BigInts] Kotlin: ___/___ [can use (operators): shr/ushr] [note: can't use ushr with unsigned integers] PHP: ___/___ [can use: >>] Python: operator.rshift/___ [can use: >>] R: ___/bitwShiftR [note: bitwShiftR appears to return unsigned, unless the shift is 0, which maintains the sign] Ruby: ___/___ [can use: >>] Rust: ___/___ [can use: >>] Scala: ___/___ [can use: >> >>>] SQL (MySQL): ___/___ [can use: >>] SQL (PostgreSQL): ___/___ [can use: >>] SQL (SQLite): ___/___ [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 SQL (MySQL): ___/___ SQL (PostgreSQL): ___/___ SQL (SQLite): ___/___ Swift: ___/___ UFL: MRound [or RoundMult][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: ___ SQL (MySQL): ___ SQL (PostgreSQL): ___ SQL (SQLite): ___ 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)][note: whether values in ascending/descending order determines whether tiebreaker is below/above needle value][see also: ArrNearest] AutoHotkey: ___ C++: ___ C#: ___ Crystal: ___ Excel: ___ Excel VBA: ___ Go: ___ Java: ___ JavaScript: ___ [can use (note: inefficiently repeats calculations, and doesn't break early if exact match found) (note: tiebreaker: < returns first match, change to <= to return last match): vNearest = oArray.reduce((a,v)=>Math.abs(vNum-v)<Math.abs(vNum-a)?v:a)] Kotlin: ___ PHP: ___ Python: ___ R: ___ Ruby: ___ Rust: ___ Scala: ___ SQL (MySQL): ___ SQL (PostgreSQL): ___ SQL (SQLite): ___ Swift: ___ UFL: (NumToRom)/(RomToNum) [Arabic numerals to Roman numerals, and vice versa][e.g. 3999 = MMMCMXCIX (typical max since no char for 4000), 1666 = MDCLXVI (every char), 888 = DCCCLXXXVIII, 444 = CDXLIV] AutoHotkey: ___/___ C++: ___/___ C#: ___/___ Crystal: ___/___ Excel: ROMAN/ARABIC [note: ARABIC (Excel 2013)] Excel VBA: WorksheetFunction.Roman/WorksheetFunction.Arabic [note: ARABIC (Excel 2013)] 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: ___/___ SQL (MySQL): ___/___ SQL (PostgreSQL): ___/___ SQL (SQLite): ___/___ 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: GAMMA (Excel 2013)] Excel VBA: WorksheetFunction.Gamma [note: GAMMA (Excel 2013)] Go: math.Gamma Java: ___ JavaScript: ___ Kotlin: ___ PHP: ___ Python: math.gamma R: gamma Ruby: Math.gamma Rust: ___ Scala: ___ SQL (MySQL): ___ SQL (PostgreSQL): ___ SQL (SQLite): ___ Swift: tgamma UFL: Erf [error function][e.g. Erf(0) = 0, Erf(2) = 0.995322..., Erf(-2) = -0.995322...][related terms: normal distribution, standard normal distribution, cumulative distribution function] 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: ___ SQL (MySQL): ___ SQL (PostgreSQL): ___ SQL (SQLite): ___ Swift: erf UFL: (Pi) [constant or function][pi=3.1415926535...][for a circle: diameter * pi = circumference, c = pi*d = 2*pi*r][pi = 4*atan(1) = acos(-1) = atan2(y=0,x=-1)] AutoHotkey: ___ [can use: vPi := 4*ATan(1)] C++: ___ [e.g. vPi = std::numbers::pi] [also: M_PI, 4*atan(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] SQL (MySQL): pi [e.g. pi()] SQL (PostgreSQL): pi [e.g. pi()] SQL (SQLite): pi [e.g. 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][see also: StrToFloat] 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] SQL (MySQL): ___ [WARNING: MySQL often returns NULL where NaN is expected e.g. 1.0/0.0] SQL (PostgreSQL): ___ [can use: 'NaN'::float] SQL (SQLite): ___ [WARNING: SQLite often returns NULL where NaN is expected e.g. 1.0/0.0] 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][note: -ln(0) = infinity][see also: StrToFloat] 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] SQL (MySQL): ___ SQL (PostgreSQL): ___ [can use: 'Infinity'::float] SQL (SQLite): ___ [can use: 1e999] [note: a float above the float64 range is stored as +infinity] Swift: ___ [e.g. vInf = Double.infinity] [also: vInf = Double("infinity")!] [also: vInf = Double("inf")!] UFL: (NgvInfinity) [or NegativeInfinity][generate negative infinity][note: ln(0) = -infinity][see also: StrToFloat] 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] SQL (MySQL): ___ SQL (PostgreSQL): ___ [can use: '-Infinity'::float] SQL (SQLite): ___ [can use: -1e999] [note: a float below the float64 range is stored as -infinity] 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: ___/___/___ [can use: vIsNaN = (InStr("" & vNum, "NAN") <> 0)] [WARNING: (vNum = vNum) to compare values, throws if passed a NaN] 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: Number.isNaN/Number.isFinite/___ [WARNING: isNaN/isFinite (without 'Number.') coerce non-numbers to numbers, then check the value, the 'Number.' versions are stricter, they return false for non-numbers, then check the value] 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 SQL (MySQL): ___/___/___ [note (check is null): (MyCol IS NULL)] SQL (PostgreSQL): ___/___/___ [note (check is finite): can compare against +/- infinity, and NaN: (MyCol != 'Infinity'::float) AND (MyCol != '-Infinity'::float) AND (MyCol != 'NaN'::float)] [MAJOR WARNING: 'NaN'::float = 'NaN'::float returns true] SQL (SQLite): ___/___/___ [note (check is finite): can compare against +/- infinity, and null: (MyCol != 1e999) AND (MyCol != -1e999) AND (MyCol IS NOT NULL)] 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.Abs(0.0)] [MAJOR WARNING: -0.0 returns 0.0] [also: vNZ := math.Copysign(0.0, -1)] [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] SQL (MySQL): ___ [e.g. -0.0] [WARNING: 'SELECT -0.0' prints 0.0] [MAJOR WARNING: attempts to store -0.0 in a table, store 0.0 (or 0)] SQL (PostgreSQL): ___ [e.g. -0.0] [WARNING: 'SELECT -0.0' prints 0.0] [MAJOR WARNING: attempts to store -0.0 in a table, store 0.0 (or 0)] SQL (SQLite): ___ [e.g. -0.0] [WARNING: 'SELECT -0.0' prints 0.0] [MAJOR WARNING: attempts to store -0.0 in a table, store 0.0 (or 0)] Swift: ___ [e.g. vNZ = -0.0] UFL: (IsNgvZero) [or IsNegativeZero][check if a number is negative zero][for atan2(y,x): atan2(0,0.0) = 0, atan2(0,-0.0) = pi][check that 'is negative zero' returns false for NaN][see also: SignBit] AutoHotkey: ___ [can use: vIsNZ := vNum ? 0 : !!ATan2(0, vNum)] [also: vIsNZ := vNum ? 0 : !!DllCall("msvcrt\atan2", "Double",0, "Double",vNum, "Cdecl Double")] [also: vIsNZ := vNum ? 0 : (DllCall("msvcrt\_copysign", "Double",1, "Double",vNum, "Cdecl Double") < 0)] 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 = IsNumeric(vNum) And ("" & vNum = "0") And (WorksheetFunction.Text(vNum, "") = "-")] [can use (throws if passed a NaN): vIsNZ = (vNum = 0) And (WorksheetFunction.Text(vNum, "") = "-")] [also (1/num approach, throws if passed a NaN): vIsNZ = (vNum = 0) And (vTemp < 0)] [beforehand (1/num approach): 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.Abs(0.0)] Java: ___ [can use: vIsNZ = (vNum == 0) && (Math.copySign(1.0, vNum) < 0)] [also: separates positive/negative zero: Arrays.sort(oArray)] JavaScript: ___ [can use: vIsNZ = (vNum === 0) && (1/vNum < 0)] [also: vIsNZ = (vNum === 0) && (1/vNum === -Infinity)] [note: Object.is(0.0, -0.0) returns false] [note: Math.atan2(0, -0.0) returns pi] 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] [also: separates positive/negative zero: oArray.sort()] 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)] [note: (-0.0).hex() returns a string that starts with '-'] R: ___ [can use: vIsNZ = !is.na(vNum) && !is.null(vNum) && (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)] [also: separates positive/negative zero: oArray = oArray.sorted] SQL (MySQL): ___ [WARNING: atan2(0,-0.0) returning 0 not pi] SQL (PostgreSQL): ___ [WARNING: atan2(0,-0.0) returning 0 not pi] SQL (SQLite): ___ [can use: (MyCol IS NOT NULL) AND (MyCol == 0) AND (atan2(0, MyCol) != 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)] SQL (MySQL): greatest [e.g. greatest(1, 2, 3)] [also (for tables): max(MyCol) FROM MyTable] SQL (PostgreSQL): greatest [e.g. greatest(1, 2, 3)] [also (for tables): max(MyCol) FROM MyTable] SQL (SQLite): max [e.g. max(1, 2, 3)] [also (for tables): max(MyCol) FROM MyTable] 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)] SQL (MySQL): least [e.g. least(1, 2, 3)] [also (for tables): min(MyCol) FROM MyTable] SQL (PostgreSQL): least [e.g. least(1, 2, 3)] [also (for tables): min(MyCol) FROM MyTable] SQL (SQLite): min [e.g. min(1, 2, 3)] [also (for tables): min(MyCol) FROM MyTable] 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 [e.g. WorksheetFunction.Sum(vNum1, vNum2, vNum3)] Go: ___ Java: ___ [note: Integer.sum handles 2 numbers] JavaScript: ___ [note: Math.addExact handles 2 numbers] Kotlin: ___ [note: Integer.sum handles 2 numbers] PHP: ___ Python: ___ [note: sum handles 2 numbers] R: sum [e.g. sum(vNum1, vNum2, vNum3)] Ruby: ___ Rust: ___ Scala: ___ [note: Integer.sum handles 2 numbers] [e.g. Integer.sum(vNum1, vNum2)] SQL (MySQL): ___ [can use (for tables): sum(MyCol) FROM MyTable] [also: sum(value) FROM json_table('[1,2,3,4]','$[*]' columns(value INT PATH '$')) t] SQL (PostgreSQL): ___ [can use (for tables): sum(MyCol) FROM MyTable] [also: sum(v) FROM unnest(ARRAY[1, 2, 3, 4]) v] SQL (SQLite): ___ [can use (for tables): sum(MyCol) FROM MyTable] [also: total(): works slightly differently from sum()] [also: sum(value) FROM json_each('[1,2,3,4]')] Swift: ___ UFL: (Product) [multiply n numbers][see also: Array.Product] AutoHotkey: ___ C++: ___ C#: ___ Crystal: ___ Excel: PRODUCT Excel VBA: WorksheetFunction.Product [e.g. WorksheetFunction.Product(vNum1, vNum2, vNum3)] Go: ___ Java: ___ JavaScript: ___ [note: Math.multiplyExact handles 2 numbers] Kotlin: ___ PHP: ___ Python: ___ [note: math.prod handles 2 numbers] R: prod [e.g. prod(vNum1, vNum2, vNum3)] Ruby: ___ Rust: ___ Scala: ___ SQL (MySQL): ___ [can use (for tables): see 'Array.Product'] SQL (PostgreSQL): ___ [can use (for tables): see 'Array.Product'] SQL (SQLite): ___ [can use (for tables): see 'Array.Product'] Swift: ___ UFL: (Mean) [see also: Array.Mean] AutoHotkey: ___ C++: ___ C#: ___ Crystal: ___ Excel: AVERAGE Excel VBA: WorksheetFunction.Average [e.g. WorksheetFunction.Average(vNum1, vNum2, vNum3)] Go: ___ Java: ___ JavaScript: ___ Kotlin: ___ PHP: ___ Python: ___ [can use (lists): statistics.mean] R: ___ [WARNING: mean() expects a vector, not raw numbers] Ruby: ___ Rust: ___ Scala: ___ SQL (MySQL): ___ [can use (for tables): avg(MyCol) FROM MyTable] [also: avg(value) FROM json_table('[1,2,3,4]','$[*]' columns(value INT PATH '$')) t] SQL (PostgreSQL): ___ [can use (for tables): avg(MyCol) FROM MyTable] [also: avg(v) FROM unnest(ARRAY[1, 2, 3, 4]) v] SQL (SQLite): ___ [can use (for tables): avg(MyCol) FROM MyTable] [also: avg(value) FROM json_each('[1,2,3,4]')] Swift: ___ UFL: (Median) [see also: Array.Median] AutoHotkey: ___ C++: ___ C#: ___ Crystal: ___ Excel: MEDIAN Excel VBA: WorksheetFunction.Median [e.g. WorksheetFunction.Median(vNum1, vNum2, vNum3)] Go: ___ Java: ___ JavaScript: ___ Kotlin: ___ PHP: ___ Python: ___ [can use (lists): statistics.median] R: ___ [WARNING: median() expects a vector, not raw numbers] Ruby: ___ Rust: ___ Scala: ___ SQL (MySQL): ___ SQL (PostgreSQL): ___ SQL (SQLite): ___ Swift: ___ UFL: (Mode) [or Modes][note: return all mode values][see also: Array.Mode] AutoHotkey: ___ C++: ___ C#: ___ Crystal: ___ Excel: MODE.MULT [WARNING: MODE: returns one mode (even if there are multiple modes), fails if the mode has frequency 1] [note: MODE.MULT (Excel 2010)] Excel VBA: WorksheetFunction.Mode_Mult [WARNING: WorksheetFunction.Mode: requires an array, returns one mode (even if there are multiple modes), throws if the mode has frequency 1] [note: MODE.MULT (Excel 2010)] Go: ___ Java: ___ JavaScript: ___ Kotlin: ___ PHP: ___ Python: ___ [can use (lists): 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: ___ SQL (MySQL): ___ SQL (PostgreSQL): ___ [can use (one mode only): e.g. mode() WITHIN GROUP (ORDER BY v) AS m FROM unnest(ARRAY[1, 2, 3, 3, 4, 4]) v] SQL (SQLite): ___ Swift: ___ UFL: (AddSafe)/(SubSafe)/(MulSafe)/(DivSafe)/(PowSafe) [arithmetic functions, 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/___/___ SQL (MySQL): ___/___/___/___/___ SQL (PostgreSQL): ___/___/___/___/___ SQL (SQLite): ___/___/___/___/___ Swift: ___/___/___/___/___ UFL: RandomInt [random(a,b) inclusive][ideally with a separate RandomSeed function] AutoHotkey: Random [e.g. Random(vMin, vMax)] [deprecated: AHK v1 had seed functionality, (unfortunately) AHK v2 doesn't] 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] SQL (MySQL): ___ [can use: MyMin + floor(rand()*(MyMax-MyMin+1))] SQL (PostgreSQL): ___ [can use: MyMin + floor(random()*(MyMax-MyMin+1))] SQL (SQLite): ___ [can use: MyMin + abs(random() % (MyMax-MyMin+1))] [WARNING: slight bias] [note: random() returns an int between -9223372036854775808 and +9223372036854775807 inclusive] [note: we avoid abs(random()), since abs(-9223372036854775808) would cause an int overflow error] 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)] SQL (MySQL): ___ [e.g. 1 + floor(rand()*6)] SQL (PostgreSQL): ___ [e.g. 1 + floor(random()*6)] SQL (SQLite): ___ [e.g. 1 + abs(random() % 6)] [WARNING: slight bias] 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] SQL (MySQL): rand [e.g. rand()] [also: rand(MySeed)] SQL (PostgreSQL): rand [e.g. random()] [also: setseed(MySeed)] SQL (SQLite): ___ [can use: random() / 18446744073709551616 + 0.5] [note: random() returns an int between -9223372036854775808 and +9223372036854775807 inclusive] Swift: random [e.g. Double.random(in:0..<1)] UFL: Format [or StrFormat][produce text in a similar way to sprintf (using string interpolation): a format string and parameters][the examples below generate '123 abc 456.789'][see also: RoundDP/SymInterpolateDemo/StrPadZero] AutoHotkey: Format [e.g. Format("{} {} {:.3f}", 123, "abc", 456.7891)] C++: std::format [e.g. std::format("{} {} {:.3f}", 123, "abc", 456.7891)] [also: sprintf/vsprintf] [requires (format): #include <format>] [WARNING (on cpp.sh): used '(double)123' to suppress error message re. ambiguous types] C#: String.Format [e.g. String.Format("{0} {1} {2:f3}", 123, "abc", 456.7891)] Crystal: sprintf [e.g. sprintf("%d %s %.3f", 123, "abc", 456.7891)] Excel: ___ Excel VBA: ___ Go: fmt.Sprintf [e.g. fmt.Sprintf("%d %s %.3f", 123, "abc", 456.7891)] Java: String.format [e.g. String.format("%d %s %.3f", 123, "abc", 456.7891)] JavaScript: ___ [can use: template strings] [also: Intl.NumberFormat] Kotlin: String.format [e.g. String.format("%d %s %.3f", 123, "abc", 456.7891)] PHP: sprintf [e.g. sprintf("%d %s %.3f", 123, "abc", 456.7891)] Python: str.format [e.g. "{} {} {:.3f}".format(123, "abc", 456.7891)] R: sprintf [e.g. sprintf("%d %s %.3f", 123, "abc", 456.7891)] Ruby: sprintf [e.g. sprintf("%d %s %.3f", 123, "abc", 456.7891)] [also (%): "%.3f" % 456.7891] Rust: format [e.g. format!("{} {} {:.3}", 123, "abc", 456.7891)] Scala: String.format [e.g. String.format("%d %s %.3f", 123, "abc", 456.7891)] [also: f"$vNum%d $vText%s $vFloat%.3f"] [also (beforehand): var vNum = 123; var vText = "abc"; var vFloat = 456.7891] [also: f"${123}%d ${"abc"}%s ${456.7891}%.3f"] SQL (MySQL): ___ [can use: e.g. concat_ws(' ', 123, 'abc', round(456.7891, 3))] SQL (PostgreSQL): format [e.g. format('%s %s %s', 123, 'abc', round(456.7891, 3))] [WARNING: only has '%s' specifier (and special %I/%L specifiers)] SQL (SQLite): format [e.g. format('%d %s %.3f', 123, 'abc', 456.7891)] [alias (deprecated): printf] Swift: String [note: with format options] [e.g. String(format:vFormat, arguments:oArray)] [e.g. String(format:vFormat, vNum)] [e.g. String(format:"%d %@ %.3f", 123, "abc", 456.7891)] [requires: import Foundation] UFL: (FormatHexDemo) [dec to hex using the format/sprintf function][e.g. 255 to 'ff' (lower case)][see also: DecToHex] AutoHotkey: Format("{:x}", 255) C++: std::format("{:x}", 255) [requires (format): #include <format>] [WARNING (on cpp.sh): didn't work, would use '{}' and '(double)255' to suppress error message re. ambiguous types, but not working because '{:x}' expects an integer type] C#: String.Format("{0:x}", 255) Crystal: sprintf("%x", 255) Excel: ___ Excel VBA: ___ Go: fmt.Sprintf("%x", 255) Java: String.format("%x", 255) JavaScript: ___ Kotlin: String.format("%x", 255) PHP: sprintf("%x", 255) Python: "{:x}".format(255) R: sprintf("%x", 255) Ruby: sprintf("%x", 255) [also (%): "%x" % 255] Rust: format!("{:x}", 255) Scala: String.format("%x", 255) [also: f"${255}%x"] SQL (MySQL): ___ SQL (PostgreSQL): ___ SQL (SQLite): format('%x', 255) [alias (deprecated): printf] Swift: String(format:"%x", 255) [requires: import Foundation] UFL: (FormatBinDemo) [dec to bin using the format/sprintf function][e.g. 255 to '11111111'][see also: DecToBin] AutoHotkey: ___ [WARNING: not handled: Format("{:b}", vNum)] C++: std::format("{:b}", 255) [requires (format): #include <format>] [WARNING (on cpp.sh): didn't work, would use '{}' and '(double)255' to suppress error message re. ambiguous types, but not working because '{:b}' expects an integer type] C#: String.Format("{0:b}", 255) Crystal: sprintf("%b", 255) Excel: ___ Excel VBA: ___ Go: fmt.Sprintf("%b", 255) Java: ___ [WARNING: 'b' for bool, not bin: String.format("%b", vBool)] JavaScript: ___ Kotlin: ___ [WARNING: 'b' for bool, not bin: String.format("%b", vBool)] PHP: sprintf("%b", 255) Python: "{:b}".format(255) R: ___ [WARNING: not handled: sprintf("%b", vNum)] Ruby: sprintf("%b", 255) [also (%): "%b" % 255] Rust: format!("{:b}", 255) Scala: ___ [WARNING: 'b' for bool, not bin: String.format("%b", vBool)] [also: f"${true}%b"] SQL (MySQL): ___ SQL (PostgreSQL): ___ SQL (SQLite): ___ Swift: ___ [WARNING: not handled: String(format:"%x", vNum)] [requires: import Foundation] UFL: StrPadZero [or FormatPadZero/StrFormatPadZero][pad integer with leading zeros][the examples below generate '0012' (and '-012' if -12 used) unless stated][see also: StrPadLeft/StrPadRight/StrPadBoth] AutoHotkey: Format [e.g. Format("{:04.0f}", 12)] [e.g. (non-negative ints): Format("{:04}", 12)] [WARNING: Format("{:04}", -12) returns '0-12', not '-012'] C++: std::format [e.g. std::format("{:04d}", 12)] [also: std::format("{:04.0f}", (double)12)] [requires (format): #include <format>] C#: String.Format [e.g. (via ';' section separator): String.Format("{0:0000;-000}", 12)] [e.g. (non-negative ints): String.Format("{0:d4}", 12)] [WARNING: String.Format("{0:d4}", -12) returns '-0012', not '-012'] Crystal: sprintf [e.g. sprintf("%04d", 12)] Excel: ___ Excel VBA: ___ Go: fmt.Sprintf [e.g. fmt.Sprintf("%04d", 12)] Java: String.format [e.g. String.format("%04d", 12)] JavaScript: ___ [can use: vText = (vNum>=0?"":"-") + "0".repeat(Math.max(vLen-vNum.toString().length,0)) + Math.abs(vNum)] [also: template strings] Kotlin: String.format [e.g. String.format("%04d", 12)] PHP: sprintf [e.g. sprintf("%04d", 12)] Python: str.format [e.g. "{:04d}".format(12)] [also: str.zfill, e.g. str(12).zfill(4)] R: sprintf [e.g. sprintf("%04d", 12)] Ruby: sprintf [e.g. sprintf("%04d", 12)] [also (%): "%04d" % 12] Rust: format [e.g. format!("{:04}", 12)] Scala: String.format [e.g. String.format("%04d", 12)] SQL (MySQL): ___ [can use: concat(if(MyCol<0,'-',''),repeat('0',greatest(MyLen-length(MyCol),0)),abs(MyCol))] SQL (PostgreSQL): ___ [can use: e.g. replace(format((CASE WHEN MyCol>=0 THEN '%8s' ELSE '-%7s' END), abs(MyCol)), ' ', '0')] SQL (SQLite): format [e.g. format('%04d', 12)] [alias (deprecated): printf] Swift: String [e.g. String(format:"%04d", 12)] [requires: import Foundation] UFL: OrdinalSuffix [or NumGetSuffix][i.e. st/nd/rd/th (e.g. 1st/2nd/3rd/4th) (ordinal suffixes)][the algorithm aims to be short, readable, and handle all positive integers and 0 (pass abs(vNum) to handle all integers)][see also: DateGetDaySuffix] AutoHotkey: vSfx := Abs(Mod(vNum,100)-12)<=1?"th":["st","nd","rd","th"][Min(Mod(vNum+9,10),3)+1] C++: vSfx = (abs(vNum%100-12)<=1) ? "th" : std::vector<std::string>{"st","nd","rd","th"}[fmin((vNum+9)%10,3)] C#: vSfx = (Math.Abs(vNum%100-12)<=1) ? "th" : ((string[])["st","nd","rd","th"])[Math.Min((vNum+9)%10,3)] Crystal: vSfx = ((vNum%100-12).abs<=1) ? "th" : ["st","nd","rd","th"][[(vNum+9)%10,3].min] [note: can use Math.min(a, b) instead of [a, b].min] Excel: =IF(ABS(MOD(A1,100)-12)<=1,"th",MID("stndrdth",MIN(MOD(A1+9,10),3)*2+1,2)) Excel VBA: vSfx = IIf(Abs((vNum Mod 100) - 12) <= 1, "th", Mid("stndrdth", WorksheetFunction.Min(((vNum + 9) Mod 10), 3) * 2 + 1, 2)) Go: vSfx := map[bool]string{true: "th", false: []string{"st", "nd", "rd", "th"}[min((vNum+9)%10, 3)]}[math.Abs(float64(vNum%100-12)) <= 1] Java: vSfx = (Math.abs(vNum%100-12)<=1) ? "th" : new String[]{"st","nd","rd","th"}[Math.min((vNum+9)%10,3)] JavaScript: vSfx = Math.abs(vNum%100-12)<=1?"th":["st","nd","rd"][vNum%10-1]||"th" Kotlin: vSfx = if (Math.abs(vNum%100-12)<=1) "th" else arrayOf("st","nd","rd","th")[Math.min((vNum+9)%10,3)] PHP: $vSfx = (abs($vNum%100-12)<=1) ? "th" : ["st","nd","rd","th"][min(($vNum+9)%10,3)] Python: vSfx = "th" if (abs(vNum%100-12)<=1) else ["st","nd","rd","th"][min((vNum+9)%10,3)] R: vSfx = if (abs(vNum%%100-12)<=1) "th" else c("st","nd","rd","th")[min((vNum+9)%%10,3)+1] Ruby: vSfx = ((vNum%100-12).abs<=1) ? "th" : ["st","nd","rd","th"][[(vNum+9)%10,3].min] Rust: vSfx = if ((vNum%100-12 as i32).abs()<=1) {"th"} else {["st","nd","rd","th"][((vNum+9)%10).min(3) as usize]} Scala: vSfx = if (math.abs(vNum%100-12)<=1) "th" else List("st","nd","rd","th")(math.min((vNum+9)%10,3)) SQL (MySQL): if(abs((MyNum % 100) - 12) <= 1, 'th', substr('stndrdth', least(((MyNum + 9) % 10), 3) * 2 + 1, 2)) SQL (PostgreSQL): CASE WHEN (abs(MyNum%100-12)<=1) THEN 'th' ELSE substr('stndrdth', least(((MyNum + 9) % 10), 3) * 2 + 1, 2) END SQL (SQLite): iif(abs((MyNum % 100) - 12) <= 1, 'th', substr('stndrdth', min(((MyNum + 9) % 10), 3) * 2 + 1, 2)) Swift: vSfx = (abs(vNum%100-12)<=1) ? "th" : ["st","nd","rd","th"][min((vNum+9)%10,3)] UFL: FormatNum [e.g. show number separator, change decimal point char][see also: PrintShowMoreDigits] AutoHotkey: ___ C++: ___ C#: ___ Crystal: ___ [e.g. '123,456.78': (123456.78).format(".", ",")] Excel: ___ Excel VBA: ___ Go: ___ Java: ___ JavaScript: ___ [e.g. '123,456.78': oFormat.format(123456.78)] [e.g. oFormat = new Intl.NumberFormat("en")] Kotlin: ___ PHP: ___ Python: ___ R: ___ Ruby: ___ Rust: ___ Scala: ___ SQL (MySQL): format [e.g. format(MyCol, MyDP)] [note: rounds to n decimal places, and adds thousand separators to integer part] SQL (PostgreSQL): to_char [e.g. to_char(MyCol, 'FM9,999,999,999')] [MAJOR WARNING: to_char() can format badly, e.g. '#,###', if number too big for format] [also (for ints): rtrim(ltrim(MyCol::money::text, '$'), '.00')] SQL (SQLite): ___ Swift: ___ UFL: FormatNumBytes [see also: PrintShowMoreDigits] AutoHotkey: ___ C++: ___ C#: ___ Crystal: ___ [e.g. '3.0kiB': (3*1024).humanize_bytes] [e.g. '3.0KB': (3*1024).humanize_bytes(format: :JEDEC)] Excel: ___ Excel VBA: ___ Go: ___ Java: ___ JavaScript: ___ Kotlin: ___ PHP: ___ Python: ___ R: ___ Ruby: ___ Rust: ___ Scala: ___ SQL (MySQL): format_bytes [e.g. format_bytes(MyCol)] SQL (PostgreSQL): pg_size_pretty [e.g. pg_size_pretty(MyCol::bigint)] SQL (SQLite): ___ Swift: ___ UFL: (FormatNumCurrency) [see also: PrintShowMoreDigits] AutoHotkey: ___ C++: ___ C#: ___ Crystal: ___ Excel: ___ Excel VBA: ___ Go: ___ Java: ___ JavaScript: ___ [e.g. oFormat.format(123456.78)] [e.g. oFormat = new Intl.NumberFormat("en", {style:"currency", currency:"USD"})] Kotlin: ___ PHP: ___ Python: ___ R: ___ Ruby: ___ Rust: ___ Scala: ___ SQL (MySQL): ___ SQL (PostgreSQL): ___ [can use: MyCol::money::text] SQL (SQLite): ___ Swift: ___ UFL: HexToBuffer [hex string to binary data][decode] AutoHotkey: ___ C++: ___ C#: ___ Crystal: ___ Excel: ___ Excel VBA: ___ Go: ___ Java: ___ JavaScript: ___ Kotlin: ___ PHP: ___ Python: ___ R: ___ Ruby: ___ Rust: ___ Scala: ___ SQL (MySQL): unhex [e.g. unhex(MyCol)] [e.g. unhex('01020304')] SQL (PostgreSQL): decode [e.g. decode(MyCol, 'hex')] [e.g. decode('01020304', 'hex')] SQL (SQLite): unhex [e.g. unhex(MyCol)] [e.g. unhex('01020304')] Swift: ___ UFL: BufferToHex [binary data to hex string][encode] AutoHotkey: ___ C++: ___ C#: ___ Crystal: ___ Excel: ___ Excel VBA: ___ Go: ___ Java: ___ JavaScript: ___ Kotlin: ___ PHP: ___ Python: ___ R: ___ Ruby: ___ Rust: ___ Scala: ___ SQL (MySQL): hex [e.g. hex(MyCol)] [e.g. hex(x'01020304')] SQL (PostgreSQL): encode [e.g. encode(MyCol, 'hex')] [e.g. encode('\x01020304'::bytea, 'hex')] SQL (SQLite): hex [e.g. hex(MyCol)] [e.g. hex(x'01020304')] Swift: ___ UFL: Base64ToBuffer [base64 string to binary data][decode][e.g. base64 'AQIDBA==' is equivalent to hex '01020304'] AutoHotkey: ___ C++: ___ C#: ___ Crystal: ___ Excel: ___ Excel VBA: ___ Go: ___ Java: ___ JavaScript: atob [e.g. oBuffer = atob(vBase64)] [note: 'atob': 'ASCII to binary'] [e.g. atob("AQIDBA==")] Kotlin: ___ PHP: ___ Python: ___ R: ___ Ruby: ___ Rust: ___ Scala: ___ SQL (MySQL): from_base64 [e.g. from_base64('AQIDBA==')] SQL (PostgreSQL): decode [e.g. decode(MyCol, 'base64')] [e.g. decode('AQIDBA==', 'base64')] SQL (SQLite): ___ Swift: ___ UFL: BufferToBase64 [binary data to base64 string][encode][e.g. base64 'AQIDBA==' is equivalent to hex '01020304'] AutoHotkey: ___ C++: ___ C#: ___ Crystal: ___ Excel: ___ Excel VBA: ___ Go: ___ Java: ___ JavaScript: btoa [e.g. vBase64 = btoa(oBuffer)] [note: 'btoa': 'binary to ASCII'] [e.g. btoa("\x01\x02\x03\x04")] Kotlin: ___ PHP: ___ Python: ___ R: ___ Ruby: ___ Rust: ___ Scala: ___ SQL (MySQL): to_base64 [e.g. to_base64(x'01020304')] [e.g. to_base64(unhex('01020304'))] SQL (PostgreSQL): encode [e.g. encode(MyCol, 'base64')] [e.g. encode('\x01020304'::bytea, 'base64')] SQL (SQLite): ___ Swift: ___

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/TruncDiv/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: TruncDiv/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