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

Signed<Magnitude> #81

Open
oscbyspro opened this issue Sep 14, 2023 · 10 comments
Open

Signed<Magnitude> #81

oscbyspro opened this issue Sep 14, 2023 · 10 comments
Labels
addition oh, so shiny! maybe to do, or not to do?
Milestone

Comments

@oscbyspro
Copy link
Owner

oscbyspro commented Sep 14, 2023

The final thing I want to investigate before committing to a flexible-width solution is whether I can efficiently model the signed part as a Signed<Magnitude> wrapper. I know fixed-width is possible, but that's different.

- NBKFlexibleWidthKit
    - UIntXL
    
- NBKSignedKit
    - SInt,   Signed<UInt>
    - SIntXL, Signed<UIntXL>
@oscbyspro oscbyspro added addition oh, so shiny! maybe to do, or not to do? labels Sep 14, 2023
@oscbyspro oscbyspro added this to the v1.0.0 milestone Sep 14, 2023
@oscbyspro
Copy link
Owner Author

oscbyspro commented Sep 14, 2023

Subquestion: if it's not possible, which set of changes would enable it?

@oscbyspro
Copy link
Owner Author

oscbyspro commented Sep 15, 2023

Making Signed<Magnitude> super light-weight, with no 2's complement and no fixed-width, is also an option.


More on this: I could introduce a non-binary NBKInteger protocol, that's like Swift.Numeric + division + words.

@oscbyspro
Copy link
Owner Author

oscbyspro commented Sep 15, 2023

I do love the light-weight approach. It's a high-value-low-maintenance coffee break project.

@oscbyspro
Copy link
Owner Author

oscbyspro commented Sep 15, 2023

I would need some composable magnitude text conversion methods, but that's easy to add.

oscbyspro added a commit that referenced this issue Sep 15, 2023
oscbyspro added a commit that referenced this issue Sep 15, 2023
oscbyspro added a commit that referenced this issue Sep 15, 2023
@oscbyspro
Copy link
Owner Author

oscbyspro commented Sep 15, 2023

I'll need to make some changes, but it seems viable. I like it because it doesn't try to be something it is not, meaning it plays to its strengths and not to its weaknesses. It's much simpler that way and way easier to maintain. It also leaves a spot open for a two's complement solution, should I find the time or need it (#44).

@oscbyspro oscbyspro removed the maybe to do, or not to do? label Sep 15, 2023
@oscbyspro
Copy link
Owner Author

oscbyspro commented Sep 16, 2023

I just realized something neat. Since these modules all live within the same package, I can use #if canImport without adding any target dependencies. Edit: never-mind, I was fooled by Xcode 😞

// in NBKSignedKit/NBKSigned.swift
#if canImport(NBKFlexibleWidthKit)
import NBKFlexibleWidthKit
public typealias SIntXL = NBKSigned<UIntXL>
#endif

@oscbyspro oscbyspro mentioned this issue Sep 16, 2023
@oscbyspro
Copy link
Owner Author

I would need some composable magnitude text conversion methods, but that's easy to add.

Sign & magnitude encoding can be exposed in TextKit (#86), so I won't need another protocol method for that.

oscbyspro added a commit that referenced this issue Oct 4, 2023
@oscbyspro
Copy link
Owner Author

oscbyspro commented Oct 4, 2023

Conforming this model to Strideable is a bit of a headache at the moment, so if that's desirable I might have to add some constraints. All core integers use Int strides, so maybe that's the way to go. Or Magnitude.Stride, perhaps?

@oscbyspro oscbyspro added the maybe to do, or not to do? label Nov 3, 2023
@oscbyspro
Copy link
Owner Author

Hm. I kind of feel like this is teetering on the edge of over-engineering. Maybe I'll add a concrete sign-magnitude model to NBKFlexibleWidthKit and drop NBKSigned<Magnitude>. Dunno, I'll decide when I get to it.

@oscbyspro
Copy link
Owner Author

There's only two interesting specializations of it: UInt and UIntXL.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addition oh, so shiny! maybe to do, or not to do?
Projects
None yet
Development

No branches or pull requests

1 participant