• Do not register here on develop.twiki.org, login with your twiki.org account.
• Use View topic Item7848 for generic doc work for TWiki-6.1.1. Use View topic Item7851 for doc work on extensions that are not part of a release. More... Close
• Anything you create or change in standard webs (Main, TWiki, Sandbox etc) will be automatically reverted on every SVN update.
Does this site look broken?. Use the LitterTray web for test cases.

Item3743: Input bugs in SpreadSheetPlugin::Calc

Item Form Data

AppliesTo: Component: Priority: CurrentState: WaitingFor: TargetRelease ReleasedIn
Extension SpreadSheetPlugin Urgent Closed   minor 4.1.3, 4.2.0

Edit Form Data

Summary:
Reported By:
Codebase:
Applies To:
Component:
Priority:
Current State:
Waiting For:
Target Release:
Released In:
 

Detail

Hello!

Using SpreadSheetPlugin for electronic engineering, we encountered incorrect behaviour of the $ROUND function. Here is an example demonstrating the problem.

ROUND(0.0000275, 3) expect 0.000 got 0 WRONG
ROUND(1.0443e-05,4) expect 0 got 0 WRONG

The following patch solves the problem.

--- Calc.pm.orig        2006-12-19 09:08:00.000000000 +0300
+++ Calc.pm     2007-03-08 10:23:48.000000000 +0300
@@ -343,6 +343,12 @@
         $result =  1 if( $i > 0 );
         $result = -1 if( $i < 0 );

+    } elsif( $theFunc eq "LN" ) {
+       $result = log (_getNumber( $theAttr ) );
+
+    } elsif( $theFunc eq "EXP" ) {
+       $result = exp (_getNumber( $theAttr ) );
+
     } elsif( $theFunc eq "IF" ) {
         # IF(condition, value if true, value if false)
         my( $condition, $str1, $str2 ) = _properSplit( $theAttr, 3 );
@@ -930,14 +936,20 @@
 sub _getNumber
 {
     my( $theText ) = @_;
+warn "_getNumber($theText)";
     return 0 unless( $theText );
     $theText =~ s/([0-9])\,(?=[0-9]{3})/$1/go;          # "1,234,567" ==> "1234567"
+    if ($theText =~ /[0-9]e/i) {                        # "1.5e-3"    ==> "0.0015"
+        $theText = sprintf "%.20f", $theText;
+        $theText =~ s/0+$//;
+    }
     unless( $theText =~ s/^.*?(\-?[0-9\.]+).*$/$1/o ) { # "xy-1.23zz" ==> "-1.23"
         $theText = 0;
     }
     $theText =~ s/^(\-?)0+([0-9])/$1$2/o;               # "-0009.12"  ==> "-9.12"
     $theText =~ s/^(\-?)\./${1}0\./o;                   # "-.25"      ==> "-0.25"
     $theText =~ s/^\-0$/0/o;                            # "-0"        ==> "0"
+warn "_getNumber returning $theText";
     return $theText;
 }

@@ -945,11 +957,10 @@
 sub safeEvalPerl
 {
     my( $theText ) = @_;
-
     # Allow only simple math with operators - + * / % ( )
     $theText =~ s/\%\s*[^\-\+\*\/0-9\.\(\)]+//go; # defuse %hash but keep modulus
     # keep only numbers and operators (shh... don't tell anyone, we support comparison operators)
-    $theText =~ s/[^\!\<\=\>\-\+\*\/\%0-9\.\(\)]*//go;
+    $theText =~ s/[^\!\<\=\>\-\+\*\/\%0-9e\.\(\)]*//go;
     $theText =~ /(.*)/;
     $theText = $1;  # untainted variable
     return "" unless( $theText );

Thank you

-- TWiki:Main/SergejZnamenskij - 08 Mar 2007

Thanks Sergej, this is fixed now and posted at TWiki:Plugins/SpreadSheetPlugin.

-- TWiki:Main.PeterThoeny - 09 Mar 2007

Fixed bug introduced by above change:

  • $VALUE(Hello 123): 123

Was returning an error instead of 123.

-- PeterThoeny - 11 Mar 2007

ItemTemplate
Summary Input bugs in SpreadSheetPlugin::Calc
ReportedBy TWiki:Main.SergejZnamenskij
Codebase 4.1.1
SVN Range TWiki-4.1.2, Sat, 03 Mar 2007, build 13043
AppliesTo Extension
Component SpreadSheetPlugin
Priority Urgent
CurrentState Closed
WaitingFor

Checkins TWikirev:13108 TWikirev:13109 TWikirev:13123 TWikirev:13124
TargetRelease minor
ReleasedIn 4.1.3, 4.2.0
Edit | Attach | Watch | Print version | History: r12 < r11 < r10 < r9 < r8 | Backlinks | Raw View |  Raw edit | More topic actions
Topic revision: r12 - 2008-01-22 - KennethLavrsen
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback