# \#math

**URL:** https://forums.swift.org/tag/math/118.md

[Latest](https://forums.swift.org/latest.md) · [Categories](https://forums.swift.org/categories.md) · [Tags](https://forums.swift.org/tags.md)

---

## [Math rendering in posts](https://forums.swift.org/t/math-rendering-in-posts/22413)

<div class="topic-metadata">

**Author:** [@RMJay](https://forums.swift.org/u/RMJay)\
**Replies:** 2\
**Last updated:** [July 14, 2026, 10:03am UTC](https://forums.swift.org/t/math-rendering-in-posts/22413 "2026-07-14T10:03:44Z")

</div>

Discourse apparently has a math plugin to allow Latex style math rendering. The plugin is disabled by default and needs to be enabled in the site settings. I think it would be useful.

---

## [Does Swift not have a "lerp"?](https://forums.swift.org/t/does-swift-not-have-a-lerp/82606)

<div class="topic-metadata">

**Author:** [@Danny](https://forums.swift.org/u/Danny)\
**Replies:** 3\
**Last updated:** [October 10, 2025, 7:49pm UTC](https://forums.swift.org/t/does-swift-not-have-a-lerp/82606 "2025-10-10T19:49:27Z")

</div>

Have I missed this somewhere? I don't see it in Numerics either. This sort of thing, I mean: #expect(.mix(1, 2, 1 / 4) == 1.25) extension FloatingPoint { static func mix(\_ \`.0\`: Self, \_ \`.1\`: Self, \_ mix: Self) -\> S…

---

## [New Version VecLab 2.0 of Swift Real/Complex Vector DSP Library](https://forums.swift.org/t/new-version-veclab-2-0-of-swift-real-complex-vector-dsp-library/80477)

<div class="topic-metadata">

**Author:** [@marcuspainter](https://forums.swift.org/u/marcuspainter)\
**Replies:** 0\
**Last updated:** [June 16, 2025, 12:16am UTC](https://forums.swift.org/t/new-version-veclab-2-0-of-swift-real-complex-vector-dsp-library/80477 "2025-06-16T00:16:12Z")

</div>

Hello! I’ve updated my VecLab DSP package to follow more Swift-like conventions. The package uses Accelerate to provide real and complex vector operations. Here’s a quick summary of its features: Mixed scalar, vector, …

---

## [Issue in number multiplication with 10, 20, etc](https://forums.swift.org/t/issue-in-number-multiplication-with-10-20-etc/72788)

<div class="topic-metadata">

**Author:** [@govishal](https://forums.swift.org/u/govishal)\
**Replies:** 3\
**Last updated:** [June 28, 2024, 7:06am UTC](https://forums.swift.org/t/issue-in-number-multiplication-with-10-20-etc/72788 "2024-06-28T07:06:22Z")

</div>

Receiving some unexpected result while simple multiplication with 10 or 20, below are some sample. 11.41 \* 10 = 114.1 1.41 \* 10 = 14.1 0.41 \* 10 = 4.1 11.42 \* 10 = 114.2 1.42 \* 10 = 14.2 0.42 \* 10 = 4.2 11.43 \* 10…

---

## [\`sqrt(0)\` v \`sin(0)\` inconsistency](https://forums.swift.org/t/sqrt-0-v-sin-0-inconsistency/71536)

<div class="topic-metadata">

**Author:** [@tera](https://forums.swift.org/u/tera)\
**Replies:** 17\
**Last updated:** [May 2, 2024, 3:24pm UTC](https://forums.swift.org/t/sqrt-0-v-sin-0-inconsistency/71536 "2024-05-02T15:24:03Z")

</div>

Found a small inconsistency in math functions: import Foundation sqrt(0) // ✅ sin(0) // 🛑 error: ambiguous use of 'sin' // note: found these candidates: // public func sin(\_ x: CGFloat) -\> CGFloat // public func sin(\_ …

---

## [Swift Rational - Swift package for working with rational numbers](https://forums.swift.org/t/swift-rational-swift-package-for-working-with-rational-numbers/69344)

<div class="topic-metadata">

**Author:** [@abdel-17](https://forums.swift.org/u/abdel-17)\
**Replies:** 41\
**Last updated:** [January 19, 2024, 6:05pm UTC](https://forums.swift.org/t/swift-rational-swift-package-for-working-with-rational-numbers/69344 "2024-01-19T18:05:53Z")

</div>

Swift Rational provides the RationalModule module for working with rational numbers in Swift. RationalModule exports the Rational struct. It conforms to standard Swift protocols like AdditiveArithmetic, Numeric, Hashabl…

---

## [Add note, or new method, for full-width integer division](https://forums.swift.org/t/add-note-or-new-method-for-full-width-integer-division/31564)

<div class="topic-metadata">

**Author:** [@CTMacUser](https://forums.swift.org/u/CTMacUser)\
**Replies:** 3\
**Last updated:** [January 13, 2024, 8:11pm UTC](https://forums.swift.org/t/add-note-or-new-method-for-full-width-integer-division/31564 "2024-01-13T20:11:45Z")

</div>

(I'm not sure this should have gone into an Evolution subcategory instead.) FixedWidthInteger provides three extended division methods. The dividedReportingOverflow and remainderReportingOverflow work like the similar …

---

## [How to avoid spurious overflow in rational-number addition?](https://forums.swift.org/t/how-to-avoid-spurious-overflow-in-rational-number-addition/64888)

<div class="topic-metadata">

**Author:** [@Nevin](https://forums.swift.org/u/Nevin)\
**Replies:** 16\
**Last updated:** [January 12, 2024, 6:44pm UTC](https://forums.swift.org/t/how-to-avoid-spurious-overflow-in-rational-number-addition/64888 "2024-01-12T18:44:55Z")

</div>

Suppose one wishes to implement a rational-number type. We can see examples of this in NumericAnnex, SwiftRational, NumberKit, and presumably more projects that I did not find in a brief search. Suppose further that the…

---

## [Working on Swift Real/Complex Vector DSP Library](https://forums.swift.org/t/working-on-swift-real-complex-vector-dsp-library/68836)

<div class="topic-metadata">

**Author:** [@marcuspainter](https://forums.swift.org/u/marcuspainter)\
**Replies:** 0\
**Last updated:** [December 6, 2023, 3:32am UTC](https://forums.swift.org/t/working-on-swift-real-complex-vector-dsp-library/68836 "2023-12-06T03:32:20Z")

</div>

Hello! I've been working on a vector math/DSP library along the lines of Matlab/NumPy. It uses the Accelerate behind the scenes and adds Matlab type functions for DSP work like FFT and windows. It's fairly lightweight, u…

---

## [Working on a general algebra library for Swift](https://forums.swift.org/t/working-on-a-general-algebra-library-for-swift/65944)

<div class="topic-metadata">

**Author:** [@SylvanM](https://forums.swift.org/u/SylvanM)\
**Replies:** 4\
**Last updated:** [July 1, 2023, 10:58pm UTC](https://forums.swift.org/t/working-on-a-general-algebra-library-for-swift/65944 "2023-07-01T22:58:13Z")

</div>

Hello! I've been working on a lot of projects having to do with general algebra in Swift dealing with groups, rings, fields, etc, as well as a library for fast matrix computations that allows for parametrization of any t…

---

## [A built-in Angle type](https://forums.swift.org/t/a-built-in-angle-type/53726)

<div class="topic-metadata">

**Author:** [@jeremyabannister](https://forums.swift.org/u/jeremyabannister)\
**Replies:** 2\
**Last updated:** [December 2, 2021, 7:27am UTC](https://forums.swift.org/t/a-built-in-angle-type/53726 "2021-12-02T07:27:28Z")

</div>

I'm curious to hear people's opinions on the idea of having an Angle type in the standard library. Concretely what I'm proposing is moving the Angle struct defined in SwiftUI down into the standard library. There are ple…

---

## [Should I expect division by 2 of a BinaryFloatingPoint number to be faster than other divisions?](https://forums.swift.org/t/should-i-expect-division-by-2-of-a-binaryfloatingpoint-number-to-be-faster-than-other-divisions/43443)

<div class="topic-metadata">

**Author:** [@madbat](https://forums.swift.org/u/madbat)\
**Replies:** 4\
**Last updated:** [December 29, 2020, 11:20pm UTC](https://forums.swift.org/t/should-i-expect-division-by-2-of-a-binaryfloatingpoint-number-to-be-faster-than-other-divisions/43443 "2020-12-29T23:20:23Z")

</div>

Hello, I'm wondering whether I should expect division by 2 on a BinaryFloatingPoint (eg a Double) number to be faster than divisions by other non-power of 2 divisors (as long as the result is not a subnormal number)? F…

---

## [Math library using Swift Numerics](https://forums.swift.org/t/math-library-using-swift-numerics/42849)

<div class="topic-metadata">

**Author:** [@rfbigelow](https://forums.swift.org/u/rfbigelow)\
**Replies:** 0\
**Last updated:** [December 15, 2020, 8:10pm UTC](https://forums.swift.org/t/math-library-using-swift-numerics/42849 "2020-12-15T20:10:35Z")

</div>

I'm working through Foundations of Game Engine Development vol. 1: Mathematics by Eric Lengyel and decided to try my hand at writing a Swift package based on the material therein. I've been following the exploits of @sca…

---

## [How to calculate the distance between 2 points in a sphere (The Earth) in Swift?](https://forums.swift.org/t/how-to-calculate-the-distance-between-2-points-in-a-sphere-the-earth-in-swift/40448)

<div class="topic-metadata">

**Author:** [@Luko](https://forums.swift.org/u/Luko)\
**Replies:** 9\
**Last updated:** [September 29, 2020, 7:34pm UTC](https://forums.swift.org/t/how-to-calculate-the-distance-between-2-points-in-a-sphere-the-earth-in-swift/40448 "2020-09-29T19:34:06Z")

</div>

Hi there, Given 2 points I need to calculate the distance between them on a sphere. How can I do something like this? Thanks!

---

## [Exponents in Swift](https://forums.swift.org/t/exponents-in-swift/18337)

<div class="topic-metadata">

**Author:** [@Wildchild9](https://forums.swift.org/u/Wildchild9)\
**Replies:** 12\
**Last updated:** [July 30, 2020, 9:29pm UTC](https://forums.swift.org/t/exponents-in-swift/18337 "2020-07-30T21:29:20Z")

</div>

Overhaul of Exponents in Swift I use Foundation's pow(\_:\_:) function often when performing calculations. This function for me has one major draw back, it does not have an overload for Int. Better yet, the introduction of…

---

## [Pitch: Vector, Matrix and Shaped Types](https://forums.swift.org/t/pitch-vector-matrix-and-shaped-types/22475)

<div class="topic-metadata">

**Author:** [@RMJay](https://forums.swift.org/u/RMJay)\
**Replies:** 5\
**Last updated:** [April 3, 2019, 5:17am UTC](https://forums.swift.org/t/pitch-vector-matrix-and-shaped-types/22475 "2019-04-03T05:17:02Z")

</div>

Introduction I would like to pitch a design for how vector and matrix types could look in Swift. The type system would be upgraded to be able reason about a type's shape. Motivation Currently the Swift language does not…

---

## [EllipticCurveKit](https://forums.swift.org/t/ellipticcurvekit/15908)

<div class="topic-metadata">

**Author:** [@Sajjon](https://forums.swift.org/u/Sajjon)\
**Replies:** 1\
**Last updated:** [September 11, 2018, 5:44am UTC](https://forums.swift.org/t/ellipticcurvekit/15908 "2018-09-11T05:44:03Z")

</div>

https://github.com/Sajjon/EllipticCurveKit Elliptic Curve Cryptography in Pure Swift using EquatoinKit. Support for multiple curves, signature type and forms. let privateKey = PrivateKey\<Secp256k1\>(hex: "B7E151628AED2A…

---

## [EquationKit](https://forums.swift.org/t/equationkit/15907)

<div class="topic-metadata">

**Author:** [@Sajjon](https://forums.swift.org/u/Sajjon)\
**Replies:** 0\
**Last updated:** [September 6, 2018, 2:11pm UTC](https://forums.swift.org/t/equationkit/15907 "2018-09-06T14:11:28Z")

</div>

https://github.com/Sajjon/EquationKit Write equations in pure Swift, differentiate and/or evaluate them. let polynomial = (3\*x + 5\*y - 17) \* (7\*x - 9\*y + 23) print(polynomial) // 21x² + 8xy - 50x - 45y² + 268y - 391) le…

---

## [Float80 math function](https://forums.swift.org/t/float80-math-function/14968)

<div class="topic-metadata">

**Author:** [@strike](https://forums.swift.org/u/strike)\
**Replies:** 14\
**Last updated:** [August 7, 2018, 4:52pm UTC](https://forums.swift.org/t/float80-math-function/14968 "2018-08-07T16:52:20Z")

</div>

Hi there! Is there a way to use mathematical functions like lgamma (), tgamma () or pow () with Float80 numbers and get Float80 numbers as a result? Thanks in advance! strike
