// Int4+Numeric.swift
// Extensions
//
// Copyright © 2021-2022 Alexandre H. Saad
// Licensed under Apache License v2.0 with Runtime Library Exception
//

extension Int4: Numeric {
	public typealias Magnitude = UInt4
	
	public init?<Source>(exactly source: Source)
	where Source: BinaryInteger {
		guard let value: Self.Value = .init(exactly: source),
				-8...7 ~= value else {
			return nil
		}
		
		self.init(value: value)
	}
	
	public var magnitude: UInt4 {
		return .init(self.value.magnitude)
	}
}
