Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework sign and magnitude init #50

Closed
oscbyspro opened this issue Aug 8, 2023 · 0 comments
Closed

Rework sign and magnitude init #50

oscbyspro opened this issue Aug 8, 2023 · 0 comments
Labels
addition oh, so shiny! subtraction huh? where did it go?
Milestone

Comments

@oscbyspro
Copy link
Owner

oscbyspro commented Aug 8, 2023

Introduction

Numberick integers have these methods and they kind of suck:

static func exactly (sign: FloatingPointSign, magnitude: Magnitude) -> Self?
static func clamping(sign: FloatingPointSign, magnitude: Magnitude) -> Self

Proposal

It would be better if NBKBinaryInteger required the following instead:

init?(sign: FloatingPointSign, magnitude: Magnitude)

Motivation

  • the clamping method is trivial and not used anywhere
  • the fallible method does not match IntXL's init(sign:magnitude:) (NBKFlexibleWidthKit #33)
  • nonfallible initializers satisfy fallible protocol requirements but this is not true for methods
  • Swift propagates initialization failures but does not do the same for methods
A) self.init(sign: sign, magnitude: magnitude)

B) if let x = Self.exactly(sign: sign, magnitude: magnitude) { self = x } else { return nil }
@oscbyspro oscbyspro added addition oh, so shiny! subtraction huh? where did it go? labels Aug 8, 2023
@oscbyspro oscbyspro added this to the v0.9.0 milestone Aug 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addition oh, so shiny! subtraction huh? where did it go?
Projects
None yet
Development

No branches or pull requests

1 participant