metaeducation / rebol-issues

6 stars 1 forks source link

enable simple math on binary! datatype #1854

Closed rebolbot closed 8 years ago

rebolbot commented 13 years ago

Submitted by: pavel

add, subtract, multiply, divide, and other math functions on binary! datatype
eventually with /logical refinement to ignore overflows

CC - Data [ Version: alpha 110 Type: Wish Platform: All Category: Native Reproduce: Always Fixed-in:none ]

rebolbot commented 13 years ago

Submitted by: BrianH

AND, OR and XOR are binary operations, not math, and so work already. Ticket changed accordingly.

For ADD, SUBTRACT and such, it would require interpreting the binary as being an integer, decimal, money, whatever; the math is completely different for each. R3 can't read your mind; it can't tell what you think the binary is beyond binary data. The way to tell R3 what datatype you want your binary interpreted as is to tell R3 to convert the binary to that type, using TO-INTEGER, TO-DECIMAL, TO-MONEY, etc.

If what you want is some other kind of datatype beyond integer, decimal, money or percent, such as bigintegers or bigdecimals, please request those separately. Or wait for user-defined types and add them yourself. Or make a extension that implements functions that treat binaries as if they were bigintegers or bigdecimals. Whichever you prefer.

R3 has a pretty strong rule that binaries are binaries, the result of discussions that spanned dozens of tickets, much argument in AltME and many blogs. We deliberately removed most of the implicit conversions to and from binary (but not all), opting for explicit use of TO, INSERT and such instead. The errors that result from missing conversions are good ones; those conversions really are missing, and the developer needs to know this so they can add the right ones. Binaries don't have meaning beyond their bits - it is up to you to provide additional meaning.

As a separate issue, the math actions and natives won't get a /logical refinement that would only refer to a single type. For low-level actions, any options should apply to all types that the function applies to. If you want different behavior to apply to a specific type, make a different function for that behavior.

rebolbot commented 13 years ago

Submitted by: BrianH

This ticket is a resubmission of #988. Dismissed as that one was.