No announcement yet.

SANDBOX-0011 hfp (half floating point) in 4DGL

  • Filter
  • Time
  • Show
Clear All
new posts

  • SANDBOX-0011 hfp (half floating point) in 4DGL

    ID: SANDBOX-0010
    STATUS: 90% complete
    AUTHOR: Anna Ceguerra
    DATE: 11 August 2010
    Copyright © 2010 Anna Ceguerra

    This is an implementation of a (non-standard) half-floating point library. It has the mathematical operations of add, subtract, multiply, divide, sqrt, round, log, trig, compare & various print functions. It is not complete as I have been unable to implement pow, exp and antilog (though I had tried my best, I couldn't get it to work).

    Compiled with the main method, it takes up just over 4900 bytes, on Picaso GFX2. You can remove the main method and try to make it into a library, with sections that you can conditionally compile with your code.

    Attached in the zip file is an introduction, the 4DGL code, and the answers to the test cases in the main method.

    Hopefully this will fill in the gap for those who need a half-floating point implementation for Picaso based smart displays.

    'Til next time!



    P.S. I have just reattached the .zip file to include the code that works on Goldelox - make sure you comment out line 2 of the .4dg file. Enjoy!


    P.P.S. Thanks to Dave for pointing out how to avoid commenting out line 2 - Version 0.4.4 should do it. No commenting out necessary.

    Attached files half_floatingpoint_v0_4_4.4dg (24.5 KB) (177.7 KB)

  • #2

    Dear all,
    I have attached a new version that now works with R22 Picaso PmmC, but not the older PmmC's. For the older PmmCs, please use the previous version of the code in the above post.
    This is now in the format of a .inc file, so that it may be easily included into other projects, using the #inherit directive.
    'Til next time!
    Regards,Anna. Attached files (5.6 KB)


    • #3

      This is very usefull

      Is possible make little example ?

      Is possible make lorenz attractor ?

      Many thanks help


      • #4

        Dear JLS,
        There are examples of how to use this in the .4dg file in the first post (in the main method).
        So long as the operations are a combination of the functions I've implemented, you should be able to implement a Lorentz attractor.
        There were some bugs in the latest .inc, I have posted a fix to this file.
        Regards,Anna Attached files (6.7 KB)


        • #5

          I do not understand implementation your library.

          Sorry i beginner please example like this

           a := -0.15;

           b := 0.265;

           c := 1.25;

           d := a*b-c;

          Thanks help


          • #6

            Hi JLS,
            Here is a code snippet of part of your code:
            HTML Code:
            var e, f, temp, div;
            var a, b, c, d;
            e := 0; f := -15;
            fp16_create_whole(0, e, f, &temp);
            e := 0; f := 100;
            fp16_create_whole(0, e, f, &div);
            fp16_divide(temp, div, &a, &temp);
            ... etc
            fp16_multiply(a, b, &temp);
            fp16_subtract(temp, c, &d);
            Hope that helps,


            • #7

              Hi Anna

              My first test but not working

              #platform "uLCD-32PT_GFX2"
              #inherit "4DGL_16bitColours.fnc"
              #inherit ""

              var e, f, temp, div;
              var a, b,tx;

              func main()

              e := 0; f := 15;
              fp16_create_whole(0, e, f,temp);
              e := 0; f := 100;
              fp16_create_whole(0, e, f,div);
              fp16_divide(temp, div,a,temp);



              tx := 10*b;





              • #8

                Hi JLS,
                Don't forget the ampersand symbol indicating you're passing by address (e.g. fp16_divide(temp, div,&a,&temp); )
                it didn't appear properly on the code snippet (it appeared as "&") - sorry about that..


                • #9

                  Hi Anna

                  Very thanks help :-)


                  • #10
                    9 years later and I still need this!

                    @Anna if you are still visiting here, or @anyone who would have it or know where to find it
                    where could I find the half floating point implementation/library

                    the link for the is dead now.


                    • #11
                      Managed to find the files for you on our server, if that's any help.
                      I haven't looked at them or attempted to use them though.
                      Attached Files


                      • #12
                        Question though.
                        What display are you using?
                        Floating point is there with Diablo and it will be much faster than this library.
                        Why not use a Diablo display if you really need float?
                        Also, often you can use 'adjusted' integers, which will, again, be much faster than floats