List Commands Library for 50g

07162017, 02:40 PM
Post: #45




RE: List Commands Library for 50g
Seeking opinions about the implementation of NL→I
NL→I (Number List to Integer) is intended as an easy/fast way to convert a list of numbers into an integer. I'd guess that 99% of the time it will be used to convert a list of single decimal digits to an integer made up of those digits, something like this: Code: { 1 2 3 4 5 6 7 8 9 0 } NL→I => 1234567890 At present, the input list must contain only numbers (specifically integers or reals) or an error will result. This seems reasonable to me, as I would think that raising an error makes more sense than simply ignoring nonnumeric objects embedded in the list, and trying to come up with something reasonable to do for nonnumeric object types would erode the performance benefit. Limiting the valid input in this way still leaves room for some ambiguous input, however. Reals with a fractional part seem fairly straightforward  I just ignore the fractional part. But I'm pondering the best way to handle negative and x>=10 numbers. A potential list of numbers could be something like the following, and NL→I needs to be able to handle it appropriately: Code: { 1.8 3 15 10000.003 123456789 } My inclination is to simply ignore the sign of any digits, thus implying that every result for NL→I will be positive. That forces the user to design their own way of tracking and applying the sign of final results, which seems like a reasonable approach given the possibility of having a mixture of signed/unsigned numbers in the input. x>=10 numbers are less clear to me, though. I can think of several possibilities for those:


« Next Oldest  Next Newest »

User(s) browsing this thread: 13 Guest(s)