I just finished writing a Binary Module with a custom function (only for Integer data types at the moment) which closely mimics the built-in “bin()” function, but also includes: the ability to control the number of bytes to return and the option to automatically pad leading zeroes. The implementation is essentially achieved via a rather trivial array-based lookup “table”. In total, the module requires only .002 MB of RAM during runtime and extensive testing shows an undeniable speedup over the built-in function by a factor of 6.

It contains no declares and has no dependencies on anything other than what is provided by the language itself. The entire endeavor, with extensive code refactoring, took me only about 4 hours. It sort of makes me chuckle a bit…

Anyways, I plan to extend it to floating-point precision as well as various binary representations (signed magnitude, one’s complement, two’s complement, etc.). Eventually I’ll refactor it all over again into a larger Radix Module and include it as just one component of many in a large, purchasable Math Extensions Encrypted Source download in the online store. The plan is to (hopefully) have it completed around September/October, so be on the lookout!

Please let me know what you think! Have you ever coded any custom functions out of a need for speed? What types of mathematical topic areas or specific functions, if any, do you wish the language would have provided?

Michael,

It’s good to see others interested in extending the math capabilities for the Xojo language. I have been developing (for several years) a module/class for Xojo that provides arbitrary precision floating point accelerated with fast FFT multiplies. I have a working version that has all of the native floating point functions plus many more. For instance, I am implementing prime factorization at the moment. I have not made a decision on how to release the code but I am leaning toward open source. My code uses no plug-ins or declares as well. Some functions really need the speedup of LLVM to compete with the speed you can obtain with c-language code. The factorization code I am working on falls in that category. Have you looked at the work that Bob Delaney has done with RbCalc and the fp plugin? He has implemented functions that convert between many bases. I agree with you in that carefully optimized Xojo code can produce quite amazing results.

Bill

Hello Michael,

Almost everything that I create for business has a high degree of mathematical calculations. Some of the more math intensive calculations deal with data noise removal (take the integral of the derivative). Some math is statistical based such as Monte Carlo analysis. Almost all of this data is graphically depicted and the graph is modified with trend analysis. These examples tax the microprocessor, especially on older machines.

Yes, a binary module would be a great addition to the existing tools in Xojo. Well done!!

Eugene

XojoScript uses LLVM. So if you can spin your code off into a script which does not rely too heavily on Context calls, you should see an impressive speed boost.

I don’t think it’s practical in my case. I don’t think you can implement a large class in a script and I’m dealing with a very large code base now as well.

You can implement large and complex classes in script. But if you have existing code and/or need to pass complex values back and forth, it’s probably not worth it.