Challenge for you... - Printable Version +- QB64 Phoenix Edition (https://staging.qb64phoenix.com) +-- Forum: QB64 Rising (https://staging.qb64phoenix.com/forumdisplay.php?fid=1) +--- Forum: Code and Stuff (https://staging.qb64phoenix.com/forumdisplay.php?fid=3) +---- Forum: Programs (https://staging.qb64phoenix.com/forumdisplay.php?fid=7) +---- Thread: Challenge for you... (/showthread.php?tid=1629) |
RE: Challenge for you... - mnrvovrfc - 04-21-2023 The line containing the "2.7128F" is a comment, would not get compiled by C/C++ but... Whoever wrote that code tried to take a shortcut and failed. But a supercomputer and some other programming language would have to adopt the formula of the first post of this topic. RE: Challenge for you... - Kernelpanic - 04-22-2023 (04-20-2023, 09:23 PM)bplus Wrote:(04-20-2023, 09:13 PM)Kernelpanic Wrote: @bplus - Written out, it matches Julia. Now if I knew how to force the "...e+XXXX" I could check that. But I couldn't find it that quickly. But it is definitely somewhere in the 1565 pages of the manual. I guess so. You just have to know how to implement that in Julia. With a simple function is not complicated, Jack's program is. One would have to work through the instructions first. What I still miss in Julia is the setting with indentation(tabs) and colors. And then how to save the script. Functions in Julia RE: Challenge for you... - mnrvovrfc - 04-22-2023 Tried to install this Julia "natively" on EndeavourOS (Arch-based Linux) but it wants to install a package that would trash something needed by GIMP so... currently downloading the "generic" version from the authors' web site. Let's see how this goes. However it wouldn't be very useful if it does scientific notation on 99! This formula is just too ridiculous for any programming language to handle, requesting output of very small numbers out of computing with very large ones. Is there a jargon for such a thing? Edit: this is bad: Code: (Select All) julia> print(2*3*4*5*6*7*8*9*10) I did it that way because I don't know it it has a built-in factorial function. EDIT #2: OK read the manual. But this might not be accurate: Code: (Select All) julia> factorial(big(30)) RE: Challenge for you... - Kernelpanic - 04-22-2023 @mnrvovrfc - I don't comprehended that in Julia. I have a problem with the factorial in Julia. When testing with QB64, the same problem occurs - but somehow inexplicable, because a comparable program works. Can someone explain the problem with the QB64 program? Thanks! In Julia: In QB64 the same problem: Code: (Select All) 'Fakultaetbeispiel, siehe Julia - 22. April 2023 That is working. Practically the same program. Code: (Select All) 'Fakultaetbeispiel 2, siehe Julia - 22. April 2023 RE: Challenge for you... - mnrvovrfc - 04-22-2023 Remove this line. It is not needed in QB64. Code: (Select All) Declare Function fakultaet(n As Integer) As _Integer64 Then change the function heading to: Code: (Select All) Function fakultaet&& (n As Integer) In QB64 must use the type sigils to define the return type of a function. In Julia I guess wrap "n" and "n-1" as "big(n)" and "big(n-1)". I had to use "big()" as suggested in the manual to get factorials larger than 23 or so, that didn't wrap around signed 64-bit integer range. RE: Challenge for you... - Kernelpanic - 04-22-2023 And why does it work in the second program? The declaration is exactly the same. I know this is no longer necessary in QB64, but for me it's for clarity. RE: Challenge for you... - bplus - 04-22-2023 (04-22-2023, 09:30 PM)Kernelpanic Wrote: And why does it work in the second program? The declaration is exactly the same. This kept the program from running infinitely. Code: (Select All) If n > 0 Then Though its kinda odd it did stop and print the factorial. The first program kept subtracting 1 from n with no bottom limit. RE: Challenge for you... - Jack - 04-23-2023 @Kernelpanic you need an exit condition, something like this Code: (Select All) function fak(n::Int) or if you want big factorial Code: (Select All) function fak(n::Int) you could also use BigFloat instead of BigInt Code: (Select All) function fak(n::Int) fak(1000000) 8.263931688331240062376646103172666291135347978963873045167775885563379611039583e+5565708 RE: Challenge for you... - david_uwi - 04-23-2023 A program for big factorials (not using strings). It was written to work with QB4.5 Code: (Select All) DefInt A-S RE: Challenge for you... - Kernelpanic - 04-23-2023 @bplu & @jack Thanks. - I suspected that it was due to an explicitly specified termination condition, but it's still not really clear to me why it doesn't work without it. With each call, n is decremented until n = 0, and then . . . the program gets off track. - Well, it doesn't work without a defined termination condition. In Julia it works now too. And I have spent a few hours with the manual and trying things like (n::BigInt) etc. @mnrvovrfc, the result is correct. |