Entry
TSE: Math: Number: Float: Multiply: How to possibly multiply very long positive floats?
Jan 23rd, 2004 05:24
Knud van Eeden,
----------------------------------------------------------------------
--- Knud van Eeden --- 23 January 2004 - 04:49 am --------------------
TSE: Math: Number: Float: Multiply: How to possibly multiply very long
positive floats?
---
--- cut here ---------------------------------------------------------
FORWARD PROC Main()
FORWARD STRING PROC FNStringGetMathAddIntegerTwoS( STRING s1, STRING
s2 )
FORWARD STRING PROC FNStringGetMathMultiplyFloatTwoS( STRING s1,
STRING s2 )
FORWARD STRING PROC FNStringGetMathMultiplyIntegerTwoS( STRING s1,
STRING s2 )
// --- MAIN --- //
PROC Main()
Warn( FNStringGetMathMultiplyFloatTwoS( "9.0", "10" ) ) //
gives "90.0"
Warn( FNStringGetMathMultiplyFloatTwoS
( "31358.14134123999", "513123.413134123412341412342" ) ) //
gives "16090596514.55932224225729024572564616995658"
Warn( FNStringGetMathMultiplyFloatTwoS( "313.141", "513.12341" ) ) //
gives "160679.97773081"
END
<F12> Main()
// --- LIBRARY --- //
// library: string: get: math: multiply: float: two
(filenamemacro=getstftx.s) [kn, ri, fr, 23-01-2004 4:26:18]
STRING PROC FNStringGetMathMultiplyFloatTwoS( STRING in1S, STRING
in2S )
// e.g. PROC Main()
// e.g. Warn( FNStringGetMathMultiplyFloatTwoS( "9.0", "10" ) ) //
gives "90.0"
// e.g. Warn( FNStringGetMathMultiplyFloatTwoS
( "31358.14134123999", "513123.413134123412341412342" ) ) //
gives "16090596514.55932224225729024572564616995658"
// e.g. Warn( FNStringGetMathMultiplyFloatTwoS
( "313.141", "513.12341" ) ) // gives "160679.97773081"
// e.g. END
// e.g.
// e.g. <F12> Main()
STRING s1[255] = ""
STRING s2[255] = ""
STRING productS[255] = ""
INTEGER powerten1I = 0
INTEGER powerten2I = 0
INTEGER powertensumI = 0
INTEGER posI = 0
//
posI = Pos( ".", in1S )
//
IF posI == 0
powerten1I = 0
s1 = in1S
ELSE
powerten1I = Length( in1S ) - posI
s1 = DelStr( in1S, posI, 1 )
ENDIF
//
posI = Pos( ".", in2S )
//
IF posI == 0
powerten2I = 0
s2 = in2S
ELSE
powerten2I = Length( in2S ) - posI
s2 = DelStr( in2S, posI, 1 )
ENDIF
productS = FNStringGetMathMultiplyIntegerTwoS( s1, s2 )
powertensumI = powerten1I + powerten2I
IF powertensumI > 0
productS = InsStr( ".", productS, Length( productS ) - powertensumI
+ 1 )
ENDIF
RETURN( productS )
END
// library: string: get: math: multiply: integer: two
(filenamemacro=getstitx.s) [kn, ri, th, 22-01-2004 22:50:16]
STRING PROC FNStringGetMathMultiplyIntegerTwoS( STRING in1S, STRING
in2S )
// e.g. PROC Main()
// e.g. Warn( FNStringGetMathMultiplyIntegerTwoS( "90", "10" ) ) //
gives "900"
// e.g. Warn( FNStringGetMathMultiplyIntegerTwoS
( "3135814134123999", "513123413134123412341412342" ) ) //
gives "1609059651455932224225729024572564616995658"
// e.g. Warn( FNStringGetMathMultiplyIntegerTwoS
( "12341234123413413241", "99897123412341234123412341341234" ) ) //
gives "1232853788287226631440261349156660317741059834879394"
// e.g. END
// e.g.
// e.g. <F12> Main()
INTEGER restI = 0
INTEGER lengthminI = 0
INTEGER lengthmaxI = 0
INTEGER sumI = 0
INTEGER I = 0
INTEGER J = 0
INTEGER cminI = 0
STRING sumS[255] = ""
STRING minS[255] = ""
STRING maxS[255] = ""
STRING cminS[1] = ""
STRING cmaxS[1] = ""
STRING sumsubS[255] = ""
STRING zeroS[255] = ""
IF Length( in1S ) < Length( in2S )
minS = in1S
maxS = in2S
ELSE
minS = in2S
maxS = in1S
ENDIF
lengthminI = Length( minS )
lengthmaxI = Length( maxS )
FOR I = 1 TO lengthminI
cminS = minS[ lengthminI - I + 1 ]
cminI = Val( cminS )
sumsubS = ""
restI = 0
FOR J = 1 TO lengthmaxI
cmaxS = maxS[ lengthmaxI - J + 1 ]
sumI = ( Val( cmaxS ) * cminI ) + restI
IF sumI > 9 AND ( J <> lengthmaxI )
restI = sumI / ( 9 + 1 )
sumI = sumI MOD ( 9 + 1 )
ELSE
restI = 0
ENDIF
sumsubS = Str( sumI ) + sumsubS
ENDFOR
sumS = FNStringGetMathAddIntegerTwoS( sumS, sumsubS + zeroS )
zeroS = zeroS + "0"
ENDFOR
RETURN( sumS )
END
// library: string: get: math: add: integer: two
(filenamemacro=getstitw.s) [kn, ri, th, 22-01-2004 3:06:41]
STRING PROC FNStringGetMathAddIntegerTwoS( STRING in1S, STRING in2S )
// e.g. PROC Main()
// e.g. Warn( FNStringGetMathAddIntegerTwoS( "90", "1" ) ) //
gives "91"
// e.g. Warn( FNStringGetMathAddIntegerTwoS
( "3135814134123999", "513123413134123412341412342" ) ) //
gives "513123413137259226475536341"
// e.g. Warn( FNStringGetMathAddIntegerTwoS
( "12341234123413413241", "99897123412341234123412341341234" ) ) //
gives "99897123412353575357535754754475"
// e.g. END
// e.g.
// e.g. <F12> Main()
INTEGER restI = 0
INTEGER lengthminI = 0
INTEGER lengthmaxI = 0
INTEGER sumI = 0
INTEGER I = 0
INTEGER J = 0
STRING sumS[255] = ""
STRING minS[255] = ""
STRING maxS[255] = ""
STRING cminS[1] = ""
STRING cmaxS[1] = ""
IF Length( in1S ) < Length( in2S )
minS = in1S
maxS = in2S
ELSE
minS = in2S
maxS = in1S
ENDIF
lengthminI = Length( minS )
lengthmaxI = Length( maxS )
FOR I = 1 TO lengthmaxI
J = lengthminI - I + 1
IF J > 0
cminS = minS[ J ]
ELSE
cminS = "0"
ENDIF
cmaxS = maxS[ lengthmaxI - I + 1 ]
sumI = Val( cmaxS ) + Val( cminS ) + restI
IF sumI > 9 AND ( I <> lengthmaxI )
restI = sumI / ( 9 + 1 )
sumI = sumI MOD ( 9 + 1 )
ELSE
restI = 0
ENDIF
sumS = Str( sumI ) + sumS
ENDFOR
RETURN( sumS )
END
--- cut here ---------------------------------------------------------
---
---
Internet: see also:
---
TSE: Math: Number: Operation: Overview: Can you give an overview of
long digit operations in TSE?
http://www.faqts.com/knowledge_base/view.phtml/aid/28481/fid/1629
----------------------------------------------------------------------