Forget Arrays, use Lists or Maps.
Using a Map you might have:
B4X:Dim mapX As Map mapX.Initialize mapX.Put(2, 234) mapX.Put(3, 3456789) ' and even: mapX.Remove(2)
XYS.Put(i + j - 1, XYS.Get(i + j - 1) + x.Get(i) * y.Get(i))
I am doing tests with B4J (much more direct, more comfortable debugging).I hope to be able to run both in B4A and B4I
That's the problem.x.Get(i)
Ma per il momento... ho fameThat's the problem.
i is an Long and if you...
log(x.Get(i)) ' Null
If i was an Int...
log(x.Get(i)) ' 1 - correct.
I don't know if it would be okay for him to replace all Longs with Int or... it is necessary to investigate the reason for this problem (this anyway!)
For i = 1 To x.Size + y.Size-1
For i = 1 To x.Size -1 + y.Size-1
Dim Key As Long = 1
x.Put(Key,Key) 'VB6: x(1) = 1
XYS.Put(Key,Key) 'VB6: XYS(1) = 1
Are you sure (now I have to digest, I cannot program ?)?And it completes
As you can tell, I'm not used to B4xPages yet.![]()
I found 2 problems:
1 - your change to "replace" the Mid$ function (I created a similar function and now this part does not crash);
2 - I have yet to find out why but there are problems using a Long as a Map key.
In this part of your source:
the Map x contains: 1 (key) 1 (value).B4X:XYS.Put(i + j - 1, XYS.Get(i + j - 1) + x.Get(i) * y.Get(i))
x.Get(i) results Null only because "i" is declared as Long; if you declare it as Int, 1 is returned as expected.
Still studying
In the meantime I am attaching the B4XPages version so you can use it with B4A, B4J and B4i.
I am doing tests with B4J (much more direct, more comfortable debugging).
I found 2 problems:
1 - your change to "replace" the Mid$ function (I created a similar function and now this part does not crash);
2 - I have yet to find out why but there are problems using a Long as a Map key.
In this part of your source:
the Map x contains: 1 (key) 1 (value).B4X:XYS.Put(i + j - 1, XYS.Get(i + j - 1) + x.Get(i) * y.Get(i))
x.Get(i) results Null only because "i" is declared as Long; if you declare it as Int, 1 is returned as expected.
Still studying
In the meantime I am attaching the B4XPages version so you can use it with B4A, B4J and B4i.
I am doing tests with B4J (much more direct, more comfortable debugging).
Sub Class_Globals
Private Root As B4XView
Private xui As XUI
Dim const e As Double = 2.718281828459
End Sub
Public Sub lnchoose(n As Int,m As Int) As Double
If (m > n) Then Return 0
If (m < n/2.0) Then m=n-m
Dim s1 As Double
s1=0
Dim i As Int
For i=m+1 To n
Dim t1 As Double
t1=i
s1=s1+Logarithm(i,e)
Next
Dim s2 As Double
s2=0
Dim ub As Int
ub = n-m
For i=2 To ub
s2=s2+Logarithm(i,e)
Next
Return s1-s2
End Sub
Public Sub Combination(n As Int,m As Int) As Double
If (m > n) Then Return 0
Return Power(e,lnchoose(n,m))
End Sub
Sub Button1_Click
MsgboxAsync(Combination(1000,500),"fff") 'Result:2.702882409453408E299'
End Sub
Sub Process_Globals
Private NativeMe As JavaObject
End Sub
#If JAVA
import java.math.BigDecimal;
import java.math.RoundingMode;
public static BigDecimal computePaiLie(int n, int m) {
if(m > n || n < 0 || m < 0) {
throw new IllegalArgumentException("n must >m!");
}
return computerJC(n).divide(computerJC(n - m), 1, RoundingMode.HALF_UP);
}
public static BigDecimal computeZuhe(int n, int m) {
if(m > n || n < 0 || m < 0) {
throw new IllegalArgumentException("n must >m!");
}
//=n!/m!(n-m)!
return computerJC(n).divide((computerJC(m).multiply(computerJC(n - m)).setScale(1, RoundingMode.HALF_UP)), 1, RoundingMode.HALF_UP);
}
public static BigDecimal computerJC(int n) {
if(n < 0) {
throw new IllegalArgumentException("n must >0!");
} else if(n == 0) {
return new BigDecimal(1);
}
BigDecimal bd = new BigDecimal(1.0);
for(int i=n; i>=1; i--) {
bd = bd.multiply(new BigDecimal(i)).setScale(1, RoundingMode.HALF_UP);
}
return bd;
}
#End If
Sub Button1_Click
Dim ZuHe As String = NativeMe.RunMethod("computeZuhe", Array(5000,2500)) 'You can cal very big num'
MsgboxAsync(ZuHe,"fff")
End Sub
Thanks stevel05, your result is wrong and Not applicable to other combinations,I found two new methods,see my reply.As you can tell, I'm not used to B4xPages yet.![]()
No problem, I just got the code running, the result was yours. I have no idea what it is supposed to be doingThanks stevel05, your result is wrong