Calculations incorrect with large numbers

Bug #531141 reported by Xhacker Liu
30
This bug affects 5 people
Affects Status Importance Assigned to Milestone
GCalctool
Fix Released
High
gcalctool (Ubuntu)
Triaged
Medium
Unassigned

Bug Description

Binary package hint: gcalctool

When meets big numbers, Gcaltool 5.29.92 calculates wrong answer.
For example, "888!":
When I use python, it returns 257365811240746258261058312635496048130210642911052728912405050489847845936124604455726245537138568519919138869993820540619317156386110281318043523819271133040245050833530381384223242463725798006902411731729593770548785690354781086905842723308884801601200379052751917433951594795069246539623889566172402612394273813442913138634455511343892185394277862364138060724692422176326391957764020447386941437446725478761545107390817405634196802572153899519689487073825003215226617854722625058758294222344083356593753257086354039728300782461317497535062225687078681424411893621525850551269343434971126659954733715916782958472453656768810440701195867642664276246868388275821267618720767840980999383693936888759532254366317019814634072835535528238339276696529590492607088777154869458497157498973960649754315551943201432369267509169588502957749960541697921095814304037256642324456938413254625533153280856940717899783245778945051168906015433910286854807561451501938458959243234283134088179776468080393516478163145085578656974388367221108095677627567015952254146171246437988038149150987707167315073537790062736939314320210458720139105535344696345447770657457362031933212587185848613853398987903918414682644458052794592851305410955768885474260613862805460079057807727238845021832356538307021541713160320875576539401590159447926998635089309190781896462345990784880322764271663904123377742519178473040194012177227689415411742481696796207548195180131422419383028352271214484900120165291146804072489789248793346781239796284546531818941890571677176899236847462415968281683926928007538265304095422178343439306412724651705340187355911592282977060598094755781754218900772740050037966772213112296704368289348866131536557227203591833504468255928529993693686570881138553294753614798339407527326181492069008868558254336122129801882121115421377833709324088258996044105013303675033524073942148782155553588617920517036672360857955988473054416496830250418320295432036884294666305652837013806869131833276398423114995974063714689045182764541217341440000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.
But gcaltool returns 25736581124074625826105831263549604813021064291105272891240505048984784593612460445572624553713856851991913886999382054061931715638611028131804352381927113304024505083353038138422324246372579800690241173172959377053910000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.

ProblemType: Bug
Architecture: i386
Date: Wed Mar 3 13:25:19 2010
DistroRelease: Ubuntu 9.10
ExecutablePath: /usr/bin/gcalctool
InstallationMedia: Ubuntu 9.10 "Karmic Koala" - Release i386 (20091028.2)
NonfreeKernelModules: nvidia
Package: gcalctool 5.28.2-0ubuntu2
ProcEnviron:
 LANGUAGE=zh_CN.UTF-8
 LANG=zh_CN.UTF-8
 SHELL=/bin/bash
ProcVersionSignature: Ubuntu 2.6.31-20.57-generic
SourcePackage: gcalctool
Uname: Linux 2.6.31-20-generic i686

Tags: gcalctool
Revision history for this message
Xhacker Liu (xhacker) wrote :
Changed in gcalctool (Ubuntu):
status: New → Triaged
importance: Undecided → Low
summary: - Gcalctool calculates wrong answer
+ Wrong result for 888!
Revision history for this message
Xhacker Liu (xhacker) wrote : Re: Wrong result for 888!

Not only 888!, other big numbers can cause the bug too.

Revision history for this message
Robert Ancell (robert-ancell) wrote :

Could you give some other test cases? Thanks!

Revision history for this message
Xhacker Liu (xhacker) wrote :

88888^100:

Gcalctool:
766149387302276358647668963491427744310804798315976240953970499821711231191237430334433556085573811714287674335578790498107987999820495052364976767206745507081913259956629403143506051971715909926796633437903308858976400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

bc:
766149387302276358647668963491427744310804798315976240953970499821711231191237430334433556085573811714287674335578790498107987999820495052364976767206745507081913259956629403143506051971715909926796633437903308858978699832696595344598777484807975307251380452083847559295720545304745334889037935791289779623465801577577693300966123018918250337902527522498468494897254033434267936929202727474649572488672832848517655542855762115946055745019554297960959548960911915572020601859582331181601050853376

Revision history for this message
Oliver Joos (oliver-joos) wrote :

The test case in comment #4 is not wrong but only imprecise - numbers of digits are equal: 495.

But the description of this bug shows a severe problem with the new display routines. If the Output format is "Scientific" or "Engineering" then the display shows "2.573658112×10²²³⁴" or "257.365811241×10²²³²" which is correct. With "Decimal" I confirm it to be wrong. And if I switch to "Binary" a core is dumped!

gcalctool 5.28.x did not have this problem. It switches automatically to Scientific format if there are more than 100 digits - even when in Binary mode: 1.01110111e+1110011111110

Hint for bug hunters: with Decimal format gcalctool clips the result of 888! to 512 chars. ;-)

summary: - Wrong result for 888!
+ Wrong result for 888! (factorial of 888)
Revision history for this message
Robert Ancell (robert-ancell) wrote : Re: Wrong result for 888! (factorial of 888)

This wrong result is due to memory corruption as can be show with valgrind. This issue was still present in 5.28.

summary: - Wrong result for 888! (factorial of 888)
+ Calculations incorrect with large numbers
Changed in gcalctool (Ubuntu):
importance: Low → Medium
Changed in gcalctool:
status: Unknown → Confirmed
Revision history for this message
Enrico B. Accenti (eaccenti) wrote :

Same behaviour on 5.31.2 . I found it out summing hundreds of '9' to 1.

Changed in gcalctool:
importance: Unknown → High
Revision history for this message
Xhacker Liu (xhacker) wrote :

Why this serious bug is still not fixed?

Revision history for this message
Enrico B. Accenti (eaccenti) wrote :

Seems fixed on 6.0.1.
 Tested on
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=11.10
DISTRIB_CODENAME=oneiric
DISTRIB_DESCRIPTION="Ubuntu oneiric (development branch)"

Revision history for this message
Xhacker Liu (xhacker) wrote :

@Enrico B. Accenti
I tried 6.0.1 just now, but unluckily the issue is still exist. (I tried "888!" test case)

Changed in gcalctool:
status: Confirmed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Duplicates of this bug

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.