GNOME Bugzilla – Bug 567252
base(number,base[,length]) doesn't honor length for decimal numbers
Last modified: 2009-01-15 14:45:53 UTC
The function base(number,base[,length]) seems to work ok for bases other than 10 but if base is 10, length is ignored. base(1;10;4) returns 1 base(1;16;4) returns 0001
Reproducible with SVN head.
Created attachment 126353 [details] [review] Proposed patch: Remove the special-casing of base 10 Looks like a case of early optimisation.
This will need testing. I believe that some of the functions that use val_to_base need to return numbers, not strings.
Created attachment 126360 [details] [review] Different patch How about this way? If no "places" argument is given, return an integer. That means that xxx2DEC is not affected.
AFAICT, it's fine as a fix for the problem, but it does feel a bit sneaky to me to special-case the return type this way. Personally, I would rather see it return a string consistently and deal with conversion to an integer in the callers where needed, or have an explicit boolean parameter to control whether strings or integers are returned.
Since the doc says that it returns a string anyways, I used Rays first patch and it works like a charm for me. Thanks!
Jens, my patch is likely to change the behaviour of other functions than =BASE like =BIN2DEC and =HEX2DEC whose implementation calls the val_to_base function; Morten's patch is a better fix because it doesn't change them.
Created attachment 126431 [details] [review] Updated patch
I'd say go for it.
This problem has been fixed in the development version. The fix will be available in the next major software release. Thank you for your bug report.