# Converting back to Double

**URL:** <https://forums.swift.org/t/converting-back-to-double/54127>\
**Category:** Swift Numerics\
**Created:** [December 17, 2021, 10:25pm UTC](https://forums.swift.org/t/converting-back-to-double/54127 "2021-12-17T22:25:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![yalishanda](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/yalishanda/32/20964_2.png) [@yalishanda](https://forums.swift.org/u/yalishanda)\
**Post date:** [December 17, 2021, 10:25pm UTC](https://forums.swift.org/t/converting-back-to-double/54127/1 "2021-12-17T22:25:37Z")

</div>

Is there a way to create a `Double` from an `AlgebraicField` or `Real` type?

I have a use case where a have a function like

```swift
func f<X: AlgebraicField>(_ x: X, minimum a: X, peak b: X, maximum c: X) -> Double {
    switch x {
    case a...b: return (x - a) / (b - a)
    case b...c: return (c - u) / (x - b)
    default: return 0
    }
}

```

where I have constraint `X: AlgebraicField` but at the same time I need to be sure that I return a `Double`.

---

<div class="post-metadata">

**Author:** ![scanon](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/scanon/32/2445_2.png) [@scanon](https://forums.swift.org/u/scanon)\
**Post date:** [December 17, 2021, 11:52pm UTC](https://forums.swift.org/t/converting-back-to-double/54127/2 "2021-12-17T23:52:17Z")

</div>

`AlgebraicField` is not the protocol you want here (in particular, "minimum", "maximum", and ranges don't make sense for an arbitrary algebraic field, since it may not be ordered).

You probably want something like `BinaryFloatingPoint` instead, which would make this Just Work.
