Welcome, Guest. Please login or register.

Author Topic: 64 bit integers in SAS/C  (Read 12591 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline olsen

Re: 64 bit integers in SAS/C
« on: July 22, 2013, 08:07:25 AM »
Quote from: nOw2;741465
What's the best way to handle large numbers in SAS/C?

I want to calculate disk space for >4GB partitions. 64 bit would be ideal, but 48bit would work for now. Possibly also need to pass the numbers through library calls too, but that's a secondary issue.


Have a look at the http://aminet.net/comm/tcp/SendRawDisk.lha utility which I wrote a while ago (full source code included). It includes both 64 bit arithmetic code written in portable 'C', as well a complete set of functions for accessing "large disks" (covering both NSD/TD64, with auto-detection of some sort which handles both sets transparently).

The purpose of this utility was to make it easier to transfer disk images from my Amiga to UAE. But if you're after the arithmetic functions, please by my guest :)

Multiplication and addition are rather straightforward. The division algorithm is a tricky one, though. Would you believe that there are several different division algorithms, some more readable than others?

If you're in dire need of arithmetic algorithms, I would hesitate to recommend Knuth's "The Art of Computer Programming: Seminumerical algorithms" (chapter 4). You have to master both the language in which the implementations are written, and make something useful out of the copious notes which accompany them. Many programmers work extra hard on solving problems on their own, rather than looking them up in the Knuth ;)
 

Offline olsen

Re: 64 bit integers in SAS/C
« Reply #1 on: July 22, 2013, 09:48:16 AM »
Quote from: ChaosLord;741553
Yeah!!!!!!!!!!!!!!!!!!!!!!  Olsen saves the day!!!!!!  :banana:


Many of the problems which are still relevant were solved (or at least chipped away at) some 5-10 years ago. It's just getting harder to find the solutions. My own contribution is (correctly) filed away in the comm/tcp section of Aminet, but who'd look there for it?

It's challenging to build a good knowledge base for Amiga programming :(

Quote

I have the 2nd edition of that book from 1981.  Is that good enough?


I'm not the one to judge, but it appears that some algorithms covered in great depth and detail by Knuth have aged better than others. Also, Knuth selected the algorithms which he covered both for their importance and didactic reasons, which means that the books are not necessarily a "directory" of algorithms and the problems which they solve. For that kind of book, I'd recommend "The algorithm design manual" by Steven Skiena.

Quote

Have any new algorithms been invented since 1981?


Of course :)  For example, probabilistic algorithms (e.g. skip lists) were not invented until the late 1980'ies.
 

Offline olsen

Re: 64 bit integers in SAS/C
« Reply #2 on: July 22, 2013, 11:18:13 AM »
Quote from: ChaosLord;741565
I have the 2nd edition of that back from 2008.

Any other books I should arm myself with?


Arm against what, exactly? ;)

Now that we have the Internet (things were so much rougher in the early 2000's and before), the importance of having the right selection of books in your personal library has declined somewhat. If you follow the trail of breadcrumbs, you'll invariably find a good, comprehensive collection of algorithm documentation and implementation. Just start on the page for "Quicksort" in Wikipedia and look through the footnotes and links at the bottom of the article's page.

The one exception concerning books I would make is Steven Skiena's book ("The algorithm design manual") which I already mentioned. The first half of the book covers algorithms in general (what are these things, how do they work, how do you build them, how can you tell when there's no scalable/optimal solution for a problem), and while this part is already great, the second half is really crackers.

The second half (modestly labeled "Resources") is a catalog of algorithms, categorized by problem domain. This doesn't sound much, but each section contains a general description of what problems fall into each class and can be solved algorithmically, and then gives a list of hints that allow you to pick the best likely solution for each problem.

This helps to overcome the big obstacle you'll always have when you're looking for a good or better approach to solving a problem with an algorithm: finding one which does the job, and making an informed decision when choosing between alternatives. For example, when you have to sort small numbers of integers, what kind of algorithm will you pick? Will you use heaps, for example, or trust in a recursive algorithm? Which circumstances surrounding your need for a matching algorithm would favour heapsort over shellsort, or even merge sort?

Quote

Would you happen to know of any books that you recommend that explain every single feature that was added to C99 with examples?  Or a good article on the internet?


I can recommend "C - A reference manual" (5th edition) by Guy Steele & Sam Harbison (well, it's mainly by Guy Steele). It makes for a great reference manual, too, so the title is actually spot on and not just for show ;)
 

Offline olsen

Re: 64 bit integers in SAS/C
« Reply #3 on: July 25, 2013, 03:27:35 PM »
Quote from: nOw2;741977
Just a quick reply to say thanks as that is exactly what I was looking for. I didn't know where to start but that gets me going in the right direction.

I now have Directory Opus 5 reporting disk sizes correctly. Next job, calculations for files and directories.


Cool, so writing the stuff in the first place and putting it on Aminet for others to find it useful did turn out to be a good idea. Glad to have been of some help :)