Factorial - Printable Version +- QB64 Phoenix Edition (https://qb64phoenix.com/forum) +-- Forum: Chatting and Socializing (https://qb64phoenix.com/forum/forumdisplay.php?fid=11) +--- Forum: General Discussion (https://qb64phoenix.com/forum/forumdisplay.php?fid=2) +--- Thread: Factorial (/showthread.php?tid=854) |
Factorial - Jack - 09-05-2022 QB64 has had _Shl and Shr for a while now, they are useful for quick multiply/divide by a power of 2, here'a factorial using only addition/subtraction and shifts I can't think of a practical use for rol and ror Code: (Select All) Dim As _Integer64 N, b, c, p RE: Factorial - Kernelpanic - 09-05-2022 Interesting! Didn't even know that this is now also available in Basic. As an example, the Egyptian or Russian pawn multiplication with the shift operator (there are only problems with the formatting of the output - it doesn't always look good): Code: (Select All) 'Schiebeoperatoren in QBasic64 - 5. Sept. 2022 RE: Factorial - Jack - 09-05-2022 Hi Kernelpanic Code: (Select All) If a Mod 2 = 1 Then 'Wenn 'a' ungerade, dann 'b' addieren. Code: (Select All) If a And 1 Then 'Wenn 'a' ungerade, dann 'b' addieren. RE: Factorial - Kernelpanic - 09-05-2022 Hello Jack, thanks. The logical AND - If a is non-zero then true. A simplification, and probably faster for large calculations. |