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

VIP: Add min and max type #1923

Closed
fubuloubu opened this issue Apr 7, 2020 · 4 comments · Fixed by #2935
Closed

VIP: Add min and max type #1923

fubuloubu opened this issue Apr 7, 2020 · 4 comments · Fixed by #2935
Labels
Easy Pickings Used to denote issues that should be easy to implement help wanted VIP: Approved VIP Approved

Comments

@fubuloubu
Copy link
Member

fubuloubu commented Apr 7, 2020

Simple Summary

Add the ability to get the minimum and maximum values for a given type via min_value(type) and max_value(type). Remove value constants like ZERO_ADDRESS, MIN_UINT256, and EMPTY_BYTES32

Motivation

#1675 adds empty(type) to specify an empty section of memory filling the size of type. This can be used to simulate "default" values that the EVM provides all types. Some types deserve the ability to also specify their edge-case values, so functionality should be added to ensure this is possible. After this featureset is fully implemented, it makes sense to eliminate the standard constants that are provided with Vyper, as they can be replicated with this more advanced featureset

Specification

min_value(type)

Returns the minimum representation value of the given type (the most negative value for a given type). Raises a compilation error if the type does not have a minimum representation type (like bytes32 or address)

Throws for more complex types.

max_value(type)

Returns the maximum representation value of the given type (the most positive value for a given type). Raises a compilation error if the type does not have a maximum representation type (like bytes32 or address)

Throws for more complex types.

Built-in Constants

All built-in constants can be replicated as follows:

ZERO_ADDRESS: address = empty(address)
EMPTY_BYTES32: bytes32 = empty(bytes32)
MAX_INT128: int128 = max_value(int128)
MIN_INT128: int128 = min_value(int128)
MAX_DECIMAL: decimal = max_value(decimal)
MIN_DECIMAL: decimal = min_value(decimal)
MAX_UINT256: uint256 = max_value(uint256)
MIN_UINT256: uint256 = min_value(uint256)  # Same as empty(uint256)

Backwards Compatibility

Removes built-in constants

Dependencies

No dependencies

Copyright

Copyright and related rights waived via CC0


EDIT: Modified min and max to min_value and max_value

@charles-cooper
Copy link
Member

great VIP!

@iamdefinitelyahuman
Copy link
Contributor

I like the functionality but I'm not a fan of the names. Vyper already uses min and max as arithmetic functions returning the lower or higher of two numeric values. As described, this VIP will give these functions two completely different functionalities depending on the input(s) given.

Is there another set of function names that are just as descriptive and not already in use?

@fubuloubu
Copy link
Member Author

We can just do min_value(type) and max_value(type), which are much more descriptive

@iamdefinitelyahuman
Copy link
Contributor

👍 for min_value and max_value

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Easy Pickings Used to denote issues that should be easy to implement help wanted VIP: Approved VIP Approved
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants