Close
0%
0%

LIBCORDIC

OK this needs to be a separate thing here and well it may be on going for a bit. COORDINATE ROTATIONAL DIGITAL COMPUTER blame the 50's!

Public Chat
Similar projects worth following
247 views
0 followers
All thou some of the formulas date to the 16 - 1700's CORDIC as we know it started in 56 by one JACK E VOLDER for the resolver upgrade for B-52 Bombers blame the name on them. It is a descriptive one we going to solve problems using a clock face for a modal. Ya ever done Taylor series algorithms cpu intensive ya ever multiply by 9 by adding a zero 9*8 = 8<> Right shift for decreasing the size of the number each shift will cut the number in half . Left shift will do the opposite doubling the number.
  • STILL PRETTY GOOD ARM CORTEX A78

    EARL T09/30/2025 at 17:21 0 comments

    There is the results from my phone and the output from lscpu Slower but still neck and neck I'm going to work on log /exp and acos when I get a chance I'm in the middle of moving right now. 

  • SOME UPDATES

    EARL T09/25/2025 at 10:11 0 comments

    Ok so sin cos is working threw its entire range i tested it against math.h by writing executable that called CORDIC_fscx 4 times one for each quadrant same with math.h but sin /cos for each one neither one prints anything just calculates it running that with time so

    time ./cordic
            ./cordic  0.00s user 0.00s system 35% cpu 0.008 total
    time ./math
             ./math  0.00s user 0.00s system 82% cpu 0.003 total
    

     so there close and I've ran this test few times and my results have been all close some closer some I've even won  and I really haven't done any optimizing at all yet so. things like making CORDIC_Q part of the function should help also when i do that i could assign the . . ax ay varibles and the start for z all in one go in fact I think I could also use the cos_aprox and sin_aprox either directly or easier if i use pointer so that i don't have to assign them later . needless to say i have a game plan that I think should work also i changed the programs to print out the results and I cheated a bit i changed the input to fix point and i used the fix point result I'm going to make a makefile real quick and include this in my next commit 

    et-hp% time ./math_bm
    0.963558    0.267499 
    0.973848    -0.227202 
    -0.891207    0.453596 
    -0.239249    -0.970958 
    ./math_bm  0.00s user 0.00s system 82% cpu 0.003 total
    et-hp% time ./cordic_bm
    1019096    282915 
    1030025    -240089 
    -1041933    181513 
    -253250    -1026868 
    ./cordic_bm  0.00s user 0.00s system 81% cpu 0.003 total

    as far as everything else goes. asin works acos works up to like ,4 and then the negative which use asin work. log exp work in a range that ends round 8 sq and sqrt i got those working to like  4 and 7  I'm using logarithmic math to get to these so  

    this works but as said the limits of exp and log are also reflected here and for reasons I haven't really discovered yet they don't work at all below 1 witch kinda screws up the goal of haversine and other spherical geometry formulas. Good news math.h is no longer a dependency so there's   that and I'm going to link this project in the new README.md I'm working on now HERE THE LINK TO THE GITHUB PAGE AGAIN . \s hows that for seo work lol \s. TODO  besides what I've sad atan atan2 mod which i have no idea how I'm going to go about that but once i figure it out it will work for the trig formulas in question unlike c's fmod or mod functions . By the way if i need them  I will later 

    some of these are needed once you begin to look at celestial navigation and maybe some other things I'm going to try later but that's how you can calculate all 6 trig ratios from sin and cos if ya happen to need that for homework your welcome .    

  • NATURAL LOG AND EXP / SQUARE AND SQUARE-ROOT MAGIC OF LOGARITHMIC MATH

    EARL T09/20/2025 at 23:15 0 comments

    Ok real quick because I've ran into some issues with the I thought fixed log and exp functions when used on command line they seem to behave  inconsistently in chain ./exp $(./log 4) =1.000 but b=./log 4 \n 4.00 = ./exp b I'm not sure why but. I will explain the CORDIC log and exp functions once I figure out this bug but let me very quickly go over the magic of logarithmic math say you want the square root of a number you take the natural log  of that number 

    then divide by 2 and get the exp of the result  im rounding to 4 decimal places for read ability .

    To add to that since we are using fix point and since binary bit shift right of 1 is equal to division by 2 to find square root of a number is 

    exp((log(4)>>1))
    2
    exp((log(2)<<1))
    4

     I used 4 for this but pull out your calculator or phone or whatever you have that can do these functions I like pari/gp myself 

    ? exp(shift(log(33),-1))
    %34 = 5.7445626465380286598506114682189293182

     so there ya go magic of logarithmic now make sure that your log function is natural log some programs sometimes default to log2 or log10 {the calculator on my phone for instance defaults to log2 I don't know why ] exp seems to always work. American Practical Navigator vol 1 &2 explains this and some other things better then I could and also has a chart of logs to assist the pre-calculator navigator book was written in 1800's but is still required knowledge  for anyone who wants there captains license in america today and required reading in many courses both civilian and military . Jhpn Napier 1614 first published   Mirifici Logarithmorum Canonis Descriptio which introduced this concept that along with the invention of the chronometer by John Harrison 1735 allowed for finding longitude while at sea by celestial navigation allowing for more safer exploration and more precise navigation which for good or bad is what caused the Europe to expand empires far far beyond the landmass threw the next century. I say for good or bad because the declamation of native populations and the rampant enslavement of human beings was in all reality a result of this however the world would not be as it is today so I really don't know how to end this so .

  • CORDIC ARCSINE ARCCOSINE

    EARL T09/20/2025 at 03:53 0 comments

    My original intention was to write this second log on log exp but as I was working on asin acos I found that the paper I was working off CORDIC-Based_Computation_of_Arcsine_and_Arccosine_Functions_on_FPGA which recommends a scaling factor to be applied to the target (t) after many adjustments and attempts at getting asin within .0_ accuracy I found removing the scaling factor to result in  more accuracy using the same setup as the sin cos  and i'm going to continue testing a bit latter as .I had been stumped for 2 days on such a simple problem . 

    I would also like to explain real quick what asin and acos are they are the anti sin cos when supplied with a sin value asin will return the angle so what you asin(sin(x))=x and acos(cos(x))=x they are the inverse operations of each other hence why

    dwould be another way to write asin same applies to acos so for angle to ratio sin for ratio to angle asin .If anyone reading this wants a more complete explanation of  the trig functions just tell me I'll be happy to provide an accurate explanation to the best of my ability if  y'all know this already ignore my ignorance I only made it threw 2 years of high school and not a very good one so I'm sometimes not aware of what is common knowledge. I'm going to push to my github sometime in the next probably day once I have modified my Makefile and added the asin acos functions to my CORDIC_CAL shell so I can test them more. I'm also thinking I may need to add a 64 bit version with a greater Q say 40 and more iterations to see how accurate results can get but that is towards the future .I still have square and square root before i can attempt haversine in CORDIC. at which point I believe I can make the cor of this in to a lib or 2 libs as and write a short program that should once i remove the one round I have in fix point run without any dependencies beyond std lib . to go much further beyond haversine in that direction I will have to add atan and atan2 which will bring me closer to a full set of cordic trig functions .I do relize that some of these are not just trig functions but  and hopefully once I include some simd neon instructions so that say . The  sin(dlon/2)^2  and sin(dlan/2)^2 likewise with the cos lat1 and lat2 witch due to the nature of cordic will also produce the sin of lat1 and lat2 for finding the true heading while this may be not nessary for many real world applications.

  • SIN COS TAN

    EARL T09/18/2025 at 12:39 0 comments



    This is the first function I have got to work properly it is also the most common one there is a sin cos CORDIC function as part of the linux kernel baby steps. Step one pre-calculated lookup-table in this case

     

     in fix point I used 20 iterations now to start this we must transpose the anglte to the first quadrant  0-90 or in Radians 0 - PI / 2 all i saved the int Q for 1-4 and then used xd and yd as modifiers -1 or 1 so its a matter of multiplying the output x and y by the proper modifier to get the proper sign for the proper quadrant then its the matter of  initializing y = 0,  x = to_fix(0.625),  z = mod_fix_ang  modified for first quad  then the goal is z ==0  accomplished  like so :

    look I'm having issues this morning lets just say this formula and its inverse i keep messing it up so you go threw this  20 times the result you turn to  float with your to_float . note on this I'm using Q20  many implications I've seen use Q16 Q15 I'm using 20 because it should give or at least be capable of greater accuracy  and when working in the trig world angles top out at either PI 2*PI depending on if  - angles are used for the past first PI hemisphere so in this case numbers are small enough that are int half of float maxing at 2048 don't seem so bad .Also the nx and ny are nessary as  if x is first x will have changed in the y formula I missed this fact at first and it had me scratching my head for a while 

    this is my sin cos  i was testing it i found it to be .01+-  and it runs fast enough even with tan added sin/cos=tan  that it dosn't register  with time on my very modest 

    Architecture:                x86_64
      CPU op-mode(s):            32-bit, 64-bit
      Address sizes:             39 bits physical, 48 bits virtual
      Byte Order:                Little Endian
    CPU(s):                      4
      On-line CPU(s) list:       0-3
    Vendor ID:                   GenuineIntel
      Model name:                Intel(R) Celeron(R) N4120 CPU @ 1.10GHz
        CPU family:              6
        Model:                   122
        Thread(s) per core:      1
        Core(s) per socket:      4
        Socket(s):               1
        Stepping:                8
        CPU(s) scaling MHz:      79%
        CPU max MHz:             2600.0000
        CPU min MHz:             800.0000
        BogoMIPS:                2189.00
      

    my more final target is lpatato a-53 arm sbc from librecomputer where imgoing to try to use some neon simd  functions I'm probably gonna stick to c but who knows assembly may happen but ya a working  lib for x86_64 and an optimized? arm lib with all the functions needed to do things like haversine and trajectory formulas so sq, sin, cos, sqrt,arctan, arcsin, arcsin2, log, and exp. anyone got a more precise way to benchmark that would be awesome .I'm kinda knew at the bench marking thing  . I'm gonna update  my github after I publish this and next entry is going to be log exp . and we will look into my issue  of exp results being hampered by the low 2048 limit i was so sure would suffice because exp 8.3 blows threw that and we can talk about the magic of natural log  and exp and never needing multiplication or...

    Read more »

View all 5 project logs

  • 1
    make all

    top level just

    make || make all 

    DEPENDENCIES

    • MAKE
    • GCC
    • STDLIB
    • TESTED  ON X86_64 AND ARM CORTEZ A78 (TERMUX ON MY PHONE PIXEL 7 PRO) BUT IF YOU GOT ANYTHING ELSE IT WILL WORK FINE MOST LIKELY

    make or make all should work on  x86_64 Linux systems that have GCC and make  no dependencies  besides the test.sh needs bash and the math_bm needs math.h. CORDIC_CAL needs stdio.h and strin byg.h . the project as a whole needs stdint.h so all std lib and the math.h iës just to get something to show speed of in comparison not for any of the functions in the lib and all the stdio and strings are also for demo programs CORDIC_CAL to_float to_fix and cordic_bm math_bm  

  • 2
    CD TO build/x86_64
    cd build/x86_64

     this is where both the static libs libfixpnt.a libCORDIC.a and all executable ./CORDIC_CAL ./to_float ./to_fix ./test.sh ./cordic_bm ./math_bm. This is just if you want to run them without installing and you can put the excutables anywhere in path to install INSTALL.sh or make install installs them to ~/.local/sbin 

  • 3
    INSTALL.sh
    ./INSTALL.sh

     installs everything to ~/.local/ lib ~/.local/sbin/ for excusables  ~/.local/include/ header files ~/.local/lib/ for libfixpnt.a and libCORDIC.a also puts ~/,local/sbin on your path at least temporarily 

View all 4 instructions

Enjoy this project?

Share

Discussions

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates