Skip to content

Commit

Permalink
WIP Decimal192 + Swifitfied
Browse files Browse the repository at this point in the history
  • Loading branch information
Sajjon committed Feb 17, 2024
1 parent 2c447c5 commit 944795e
Show file tree
Hide file tree
Showing 8 changed files with 992 additions and 84 deletions.
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export RUSTC_WRAPPER=/opt/homebrew/bin/sccache
export JAVA_OPTS="-Xmx8g"
export CLASSPATH=$PWD/jna-5.13.0.jar
12 changes: 10 additions & 2 deletions .tarpaulin.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
[all]
exclude-files = [
"tests/*",
"src/wrapped_radix_engine_toolkit/dummy_types.rs",
"example/*",
"target/*",
"apple/*",
".swiftpm/*",
"scripts/*",
".build/*",
"Package.swift",
]
verbose = false
all-features = true
timeout = "1800s"
timeout = "5m"
skip-clean = true
out = ["Xml"]
force-clean = false
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
//extension Decimal192: Comparable {}
extension Decimal192 {
public init(_ string: String) throws {
self = try newDecimalFromString(string: string)
}
}

extension Decimal192: CustomStringConvertible {
public var description: String {
decimalToString(decimal: self)
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,76 @@
extension Decimal192: Sendable {}
//extension Decimal192: ExpressibleByStringLiteral {
//
//}
//extension Decimal192: ExpressibleByFloatLiteral {
//
//}
//extension Decimal192: SignedNumeric /* Numeric, ExpressibleByIntegerLiteral AdditiveArithmetic */
//{
//
//}

extension Decimal192 {
public init(_ string: String) throws {
self = try newDecimalFromString(string: string)
}
}

extension Decimal192: CustomStringConvertible {
public var description: String {
decimalToString(decimal: self)
}
}

extension Decimal192: ExpressibleByStringLiteral {
public init(stringLiteral string: String) {
try! self.init(string)
}
}
extension Decimal192: ExpressibleByIntegerLiteral {
public init(integerLiteral i64: Int64) {
self = newDecimalFromI64(value: i64)
}
}

extension Decimal192: ExpressibleByFloatLiteral {
public init(floatLiteral value: Double) {
let formatter = NumberFormatter()
formatter.numberStyle = .decimal
formatter.decimalSeparator = "." // Sargon ALWAYS uses "."
formatter.maximumFractionDigits = 18
let string = formatter.string(from: NSNumber(value: value))!
try! self.init(string)
}
}
extension Decimal192: AdditiveArithmetic {
public static var zero: Self {
newDecimalFromU64(value: 0)
}
public static func + (lhs: Self, rhs: Self) -> Self {
decimalAdd(lhs: lhs, rhs: rhs)
}
public static func - (lhs: Self, rhs: Self) -> Self {
decimalSub(lhs, rhs)
}
}
extension Decimal192: SignedNumeric {
public static func - (operand: Self) -> Self {
decimalNeg(decimal: operand)
}
}
extension Decimal192: Numeric {
public typealias Magnitude = Self

public var magnitude: Magnitude {
decimalAbs(self)
}

public static func * (lhs: Self, rhs: Self) -> Self {
decimalMul(lhs: lhs, rhs: rhs)
}

public static func *= (lhs: inout Self, rhs: Self) {
lhs = lhs * rhs
}

public init?<T>(exactly source: T) where T: BinaryInteger {
if let i64 = Int64(exactly: source) {
self = newDecimalFromI64(value: i64)
} else if let u64 = UInt64(exactly: source) {
self = newDecimalFromU64(value: u64)
} else {
return nil
}
}
}
Loading

0 comments on commit 944795e

Please sign in to comment.