• Calculation of sine with tables (was Re: why is there not a ipow version of pow?)

    From Janis Papanagnou@janis_papanagnou+ng@hotmail.com to comp.lang.c on Thu Aug 13 14:45:46 2026
    From Newsgroup: comp.lang.c

    On 2026-08-13 08:38, David Brown wrote:
    On 12/08/2026 23:49, Lynn McGuire wrote:
    [...]

    I have found over the years that 200 points seems to be best when
    performing a numerical integration of a curve.-a For me, 200 points is
    the point where diminishing returns has set in.-a Of course, YMMV.

    Your mileage may very much vary.-a The best number of points depends on
    many factors, [...]

    That's what I'd also expect. (As far as interpolation is concerned.)

    [...]

    For my own uses, I typically need things like sin functions for motor control and other such applications.-a Tables of perhaps 16 or 32 evenly spaced points, with cubic interpolation, are often fine to get the
    accuracy I need in a few clock cycles on a microcontroller.-a (I don't
    think I have ever needed a floating point "pow" on a microcontroller.)

    For the sine function I recall some ROM analysis of the PC 1401 pocket calculator I did (for fun) in my youth. Between all the hex codes of
    the assembler commands I stumbled across irregular appearing data. It
    turned out that they were used for the trigonometric functions, and I identified them as CORDIC constants back then. These tables had been, surprisingly - I didn't knew anything about the underlying math back
    then - rather small. Now with help of Google what I find interesting
    to read about those table sizes, in the binary case, and in case of
    that pocket calculator which uses internally a 12-digit BCD encoding.

    "The size of a CORDIC (COordinate Rotation DIgital Computer) angle
    lookup table equals the number of iterations (n), where each entry
    stores an arctangent value \(\arctan(2^{-i})\) matching the system's
    bit width. For standard precision targets, n matches the precision
    bit length (e.g., 16 entries for 16-bit, 32 entries for 32-bit),
    requiring only tens to hundreds of bytes."

    (Which matches with your numbers above. But from your brief mention
    I'm not sure the approach you did was comparable with or was CORDIC.)

    "The Sharp PC-1401 pocket computer relies on the Hitachi SC61860
    8-bit CMOS processor running a specialized BCD (Binary Coded Decimal)
    math library in its 40 KB internal ROM. To compute trigonometric and
    hyperbolic functions with 10 to 12 digits of precision, the ROM uses
    a customized BCD-variant of the CORDIC (Coordinate Rotation Digital
    Computer) algorithm."

    "Unlike standard binary-based CORDIC implementations that shift bits
    by \(2^{-i}\), the PC-1401 processor implements a digit-by-digit BCD
    CORDIC calculation (\(10^{-i}\) shifts).
    Table Depth (Steps): 11 to 12 entry levels (corresponding to shifts
    from 10rU# down to 10rU+-|rU# or 10rU+-|-|).
    Data Precision: Numbers are processed internally using an 8-byte
    (64-bit) BCD floating-point format.
    Total Storage Size: The lookup table for the primary rotation angles
    (\(\theta_i = \arctan(10^{-i})\)) occupies exactly 88 to 96 bytes
    of the 40 KB system ROM."

    (Smaller tables with BCD encoding.)

    "Why the Table is So Small
    Decimal Shifting: By utilizing BCD, the processor does not need a
    massive radix conversion table. It multiplies or divides by powers
    of 10 simply by shifting 4-bit nibbles across the internal
    registers.
    Interleaved Functions: The exact same loop structures and angle
    tables are shared globally between SIN, COS, TAN, and their inverse
    equivalents (ASN, ACS, ATN), saving critical space in the tightly
    packed SC613256 ROM chip."

    (And speedy BCD-shifts. - Which reminds me the discussion here about
    binary shifts in the float representation of 'pow' when using binary
    exp/log representations for optimization purposes.)

    One "hammer" (a small CORDIC table) for a whole class of functions;
    amazing.

    Janis

    PS: I'm astonished that Google has all that information - after all
    that pocket calculator things are just legacy stuff. (Around 1980,
    without the Web (or search engines), it had been really a hard job
    to find and identify all that information.)

    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From scott@scott@slp53.sl.home (Scott Lurndal) to comp.lang.c on Thu Aug 13 14:36:57 2026
    From Newsgroup: comp.lang.c

    Janis Papanagnou <janis_papanagnou+ng@hotmail.com> writes:
    On 2026-08-13 08:38, David Brown wrote:


    (And speedy BCD-shifts. - Which reminds me the discussion here about
    binary shifts in the float representation of 'pow' when using binary
    exp/log representations for optimization purposes.)

    One of the nice features of the B3500 BCD architecture was the
    speed of multiplication and division by powers of 10 by simply
    adjusting the boundaries of a move digits instruction.
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From David Brown@david.brown@hesbynett.no to comp.lang.c on Thu Aug 13 17:07:11 2026
    From Newsgroup: comp.lang.c

    On 13/08/2026 14:45, Janis Papanagnou wrote:

    One "hammer" (a small CORDIC table) for a whole class of functions;
    amazing.


    I agree - the CORDIC concept is very cool. The same structure can be
    used for trig functions, hyperbolic functions, converting between
    Cartesian and radial forms, multiplication, division, and a few other
    things - all with very simple operations.

    It is, however, slower and more complex than tables and interpolation
    for the things I needed, and slower for calculating high-accuracy transcendental functions on "big" processors than alternatives.

    Janis

    PS: I'm astonished that Google has all that information - after all
    that pocket calculator things are just legacy stuff. (Around 1980,
    without the Web (or search engines), it had been really a hard job
    to find and identify all that information.)


    Some people get really "nerdy" about calculators. (I spent a good
    proportion of my spare cash on a programmable Casio fx-3600P in my
    youth, and wrote all sorts of programs despite its 36 byte program
    memory. It is still in my desk drawer, and still works.) It is amazing
    how much detailed information people have published about various
    calculators. Google's search has got very good about summarising
    information from web pages, and helpfully gives links to the references
    it uses. But it's the work done by calculator fans (as well as people
    writing articles and Wikipedia pages about Cordic) that is astonishing
    to me, rather than how well Google finds the information.

    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Janis Papanagnou@janis_papanagnou+ng@hotmail.com to comp.lang.c on Thu Aug 13 19:07:54 2026
    From Newsgroup: comp.lang.c

    On 2026-08-13 17:07, David Brown wrote:

    [...]-a But it's the work done by calculator fans (as well as people
    writing articles and Wikipedia pages about Cordic) that is astonishing
    to me, rather than how well Google finds the information.

    Well, sure; honor to whom it deserves!

    (Thanks for catching and correcting my sloppiness.)

    Janis

    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From David Brown@david.brown@hesbynett.no to comp.lang.c on Thu Aug 13 22:24:03 2026
    From Newsgroup: comp.lang.c

    On 13/08/2026 19:07, Janis Papanagnou wrote:
    On 2026-08-13 17:07, David Brown wrote:

    [...]-a But it's the work done by calculator fans (as well as people
    writing articles and Wikipedia pages about Cordic) that is astonishing
    to me, rather than how well Google finds the information.

    Well, sure; honor to whom it deserves!

    (Thanks for catching and correcting my sloppiness.)


    I didn't see any sloppiness on your part. Even though it was mainly
    from Google, based on other people's work, it was still a post with interesting history.

    And I suppose Google deserves some credit for making a pretty good
    search engine!

    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Ross Finlayson@ross.a.finlayson@gmail.com to comp.lang.c on Thu Aug 13 16:36:18 2026
    From Newsgroup: comp.lang.c

    On 08/13/2026 01:24 PM, David Brown wrote:
    On 13/08/2026 19:07, Janis Papanagnou wrote:
    On 2026-08-13 17:07, David Brown wrote:

    [...] But it's the work done by calculator fans (as well as people
    writing articles and Wikipedia pages about Cordic) that is
    astonishing to me, rather than how well Google finds the information.

    Well, sure; honor to whom it deserves!

    (Thanks for catching and correcting my sloppiness.)


    I didn't see any sloppiness on your part. Even though it was mainly
    from Google, based on other people's work, it was still a post with interesting history.

    And I suppose Google deserves some credit for making a pretty good
    search engine!


    Google, Bing, Altavista, Webcrawler, all ate by the big fish,
    fronting the same "search and hide and huff and stuff" engine,
    "Google" deserves some debit.

    It's called a monopoly there are laws against it for the common good
    and in the interests of free-market capitalism.

    Of course the Internet is pretty great.

    Data centers should pay excise for juice,
    and bot-chat-farms should pay excise for RAM.


    I'm surprised nobody's mentioned Kuratsaba (sp.) et alia, the usual
    account of trading multiplies for additions to compute multiplication.



    --- Synchronet 3.22a-Linux NewsLink 1.2