After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 567252 - base(number,base[,length]) doesn't honor length for decimal numbers
base(number,base[,length]) doesn't honor length for decimal numbers
Status: RESOLVED FIXED
Product: Gnumeric
Classification: Applications
Component: Analytics
1.8.x
Other Linux
: Normal normal
: ---
Assigned To: Morten Welinder
Jody Goldberg
Depends on:
Blocks:
 
 
Reported: 2009-01-10 14:01 UTC by Jens Peter
Modified: 2009-01-15 14:45 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Proposed patch: Remove the special-casing of base 10 (369 bytes, patch)
2009-01-13 14:56 UTC, J.H.M. Dassen (Ray)
none Details | Review
Different patch (386 bytes, patch)
2009-01-13 17:53 UTC, Morten Welinder
none Details | Review
Updated patch (1.65 KB, patch)
2009-01-14 17:17 UTC, Morten Welinder
none Details | Review

Description Jens Peter 2009-01-10 14:01:44 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
Comment 1 J.H.M. Dassen (Ray) 2009-01-13 14:17:37 UTC
Reproducible with SVN head.
Comment 2 J.H.M. Dassen (Ray) 2009-01-13 14:56:54 UTC
Created attachment 126353 [details] [review]
Proposed patch: Remove the special-casing of base 10

Looks like a case of early optimisation.
Comment 3 Morten Welinder 2009-01-13 15:55:07 UTC
This will need testing.

I believe that some of the functions that use val_to_base need to
return numbers, not strings.
Comment 4 Morten Welinder 2009-01-13 17:53:44 UTC
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.
Comment 5 J.H.M. Dassen (Ray) 2009-01-13 18:38:16 UTC
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.
Comment 6 Jens Peter 2009-01-13 19:54:11 UTC
Since the doc says that it returns a string anyways, I used Rays first patch and it works like a charm for me.

Thanks!
Comment 7 J.H.M. Dassen (Ray) 2009-01-13 21:20:40 UTC
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.
Comment 8 Morten Welinder 2009-01-14 17:17:10 UTC
Created attachment 126431 [details] [review]
Updated patch
Comment 9 J.H.M. Dassen (Ray) 2009-01-15 14:38:08 UTC
I'd say go for it.
Comment 10 Morten Welinder 2009-01-15 14:45:53 UTC
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.