Compare App Versions After Update Using Decimals Like 2.5.2

Compare app versions after update using decimals like 2.5.2

You can simply use Foundation struct OperatingSystemVersion and create a custom initializer:

extension OperatingSystemVersion: LosslessStringConvertible {
public init?(_ string: String) {
let comps = string.split { $0 == "." }
if string.range(of: "^[0-9]+.[0-9]+.[0-9]+$", options: .regularExpression) != nil {
self.init(majorVersion: Int(comps[0]) ?? 0, minorVersion: Int(comps[1]) ?? 0, patchVersion: Int(comps[2]) ?? 0)
} else if string.range(of: "^[0-9]+.[0-9]+$", options: .regularExpression) != nil {
self.init(majorVersion: Int(comps[0]) ?? 0, minorVersion: Int(comps[1]) ?? 0, patchVersion: 0)
} else if string.range(of: "^[0-9]+$", options: .regularExpression) != nil {
self.init(majorVersion: Int(comps[0]) ?? 0, minorVersion: 0, patchVersion: 0)
} else {
return nil
}
}
public var description: String {
[majorVersion, minorVersion, patchVersion].map(String.init).joined(separator: ".")
}
}

Then you can conform OperatingSystemVersion to Comparable:

extension OperatingSystemVersion: Comparable {
public static func == (lhs: Self, rhs: Self) -> Bool {
(lhs.majorVersion, lhs.minorVersion, lhs.patchVersion) == (rhs.majorVersion, rhs.minorVersion, rhs.patchVersion)
}

public static func < (lhs: Self, rhs: Self) -> Bool {
(lhs.majorVersion, lhs.minorVersion, lhs.patchVersion) < (rhs.majorVersion, rhs.minorVersion, rhs.patchVersion)
}
}

And just check if it is older than the new version:

if let old = OperatingSystemVersion("2.5.2"),
let new = OperatingSystemVersion("2.5.3"),
old < new {
print(new.majorVersion) // "2\n"
print(new.minorVersion) // "5\n"
print(new.patchVersion) // "3\n"
}

Using Decimal parameters in Firebird stored procedures

I just discovered that I had a stale reference to Firebird Client 2.5.1 in my GAC. After removing this reference, I was able to run my test cases successfully.

The .NET Provider for Firebird version 2.5.2 does not have the problem I described in my question. The solution is to upgrade to the latest version of the .NET Provider for Firebird.

Round up from .5

This is not my own function, and unfortunately, I can't find where I got it at the moment (originally found as an anonymous comment at the Statistically Significant blog), but it should help with what you need.

round2 = function(x, digits) {
posneg = sign(x)
z = abs(x)*10^digits
z = z + 0.5 + sqrt(.Machine$double.eps)
z = trunc(z)
z = z/10^digits
z*posneg
}

x is the object you want to round, and digits is the number of digits you are rounding to.

An Example

x = c(1.85, 1.54, 1.65, 1.85, 1.84)
round(x, 1)
# [1] 1.8 1.5 1.6 1.8 1.8
round2(x, 1)
# [1] 1.9 1.5 1.7 1.9 1.8

(Thanks @Gregor for the addition of + sqrt(.Machine$double.eps).)

Check for current Node Version

Look at process.version property.



Related Topics



Leave a reply



Submit