PDA

View Full Version : Example 3 from v1.0.3.5 help file



Petr Schreiber
13-09-2005, 20:34
Hi,

I browsed the examples, and I discovered, that the third doesn't work.
It displays "Factorial of 1000 = 0" and then it produces GPF

Thanks,
Psch

P.S. The 4th example seems to do nothing too -> but it does :) Missing input file could confuse, maybe its creation could be part of the program

Petr Schreiber
13-09-2005, 20:40
The bad factorial result is possibly caused by too high nuber on input ( 1000 ). With 10 it's ok for normal function, but the GPF is still present ( maybe while processing the recursive function )

Thanks,
Psch

P.S. Last correct result is for 12!. For 13! and higher it returns unreal or negative values. My calculator form 1986 - HP-42s with 7.2 KB of RAM does it up to 253!

P.P.S. PowerBASIC using your normal function for factorial gets the same error results too, is it possible that my old good programmable calc beats them both using the same algoritm ? :)

Petr Schreiber
13-09-2005, 21:14
Now I know why it returned unreal results, numbers were outside of LONG borders. But redefining them to QUADs helped only in PB, ThinBASIC possibly don't full support of QUADs yet

Thanks,
Psch

ErosOlmi
13-09-2005, 21:25
Example 3 was from a early thinBasic version with no numeric types.
I've corrected it.

Dim msg As String
Dim count As Long
Dim N1 As Ext
Dim N2 As Ext

'---
' A simple standard function
'---
Function Factorial(InVal As Number) As Ext
Dim i As Ext
Dim r As Ext

r = 1
For i = 2 To InVal
r = r * i
Next
Function = r

End Function

'---
' A recursive function
'---
Function RecursiveExample(n As Number, MaxRecurse As Number) As EXT
Dim s As String Value Repeat$(10000, "X")

INCR n
If n >= MaxRecurse Then
Function = n
Exit Function
Else
Function = RecursiveExample(n, MaxRecurse)
End If

End Function

'---
'---Main Program
'---
N1 = 10
N2 = Factorial(N1)

MsgBox "Factorial of " & N1 & " = " & Format$(N2, "0#")
MsgBox "I've called a recursive function " & RecursiveExample(1, N1) & " times"

Dim count2 As Long
For count = 1 To 64
msg = msg & "[" & Format$(2^count) & "]"
If MOD(count,2) = 0 Then
msg = msg & crlf
Else
msg = msg + " "
End If
For count2 = 1 To 100
count2 = count2
Next
Next

MsgBox "From 2^1 to 2 ^ 64:\n" & msg




QUAD are supported in new version (the one you have now).

Example 4 does something only if you have the input file.
This example is the same you can find in directory SampleScripts\Arrays\Parse. There you will find also test input file: Test_FileLineSelect(In).TXT

Thanks
Eros

Petr Schreiber
13-09-2005, 21:33
Yes, I can confirm it's all OK now. Sorry to waste 3 replies with solving such a simple problem, but I just wanted to arrange ideas in my head :oops:

Thanks,
Psch

ErosOlmi
13-09-2005, 21:36
You "arranged ideas" also in my head.
Also, more important, if example in the help file doesn't work it will give absolutelly bad impression to possible thinBasic users.

Thanks and please continue to suggest us every thing you think should be changed.

Eros