使用 Interval 类型的 Swift 区间算术 (Interval Arithmetic)
import Interval // needed only if you "make repl"
let about1 = 1.0 ± 0.1 // 0.9...1.1
about1+about1 // 1.8...2.2
about1-about1 // -0.2...0.2
about1*about1 // 0.81...1.21
about1/about1 // 0.818181818181818...1.22222222222222
Swift 5.0 或更高版本,OS X 或 Linux。
只需将 interval.swift 添加到您的项目中即可。
尽情使用本 Git 仓库中的 Interval.playground。
当您使用它时,请确保打开左侧窗格(在您拉取代码后,它是关闭的,因为 UI 设置已通过 .gitignore
忽略)。如您所见,此 Playground 由多个页面和源文件组成。
只需将 interval.swift 拖放到 Sources
文件夹中。在 Git 中,Interval.playground/Sources/interval.swift
是指向它的符号链接。
git clone https://github.com/dankogai/swift-interval.git
cd swift-interval
make repl
git clone https://github.com/dankogai/swift-interval.git
cd swift-interval
make SWIFTPATH=${YOUR_SWIFT_PATH} repl # ${YOUR_SWIFT_PATH}=~/swift/usr/bin in my case
Swift 5 或更高版本,OS X 或 Linux 用于构建。