comp.lang.ada
 help / color / mirror / Atom feed
From: Aurele Vitali <aurele.vitali@gmail.com>
Subject: Re: GNAT for AVR - Mathematical Functions
Date: Mon, 17 Sep 2018 15:41:33 -0700 (PDT)
Date: 2018-09-17T15:41:33-07:00	[thread overview]
Message-ID: <87c83c63-f520-4f6e-a250-ad9665c8a20f@googlegroups.com> (raw)
In-Reply-To: <pnnkfd$ui6$1@gioia.aioe.org>

I don't know anything about the ATmega328P, but if it uses a builtin floating point processor, you can use Ada inline floating point assembler.  Its not hard to do. Here is a simple example of the square root function: 

  with System.Machine_Code; use System.Machine_Code; 
  EOL : constant String := ASCII.LF & ASCII.HT;

  function Sqrt( x : in Long_Float ) return Long_Float is 
    Result : Long_Float := 0.0; 
  begin 
    Asm( ( "fldl  %1" & EOL &                 -- Load x in St(0) 
           "fsqrt   " & EOL &                 -- Take the Sqrt of St(0) 
           "fstpl %0" ),                      -- Store result and pop St(0) 
         Outputs => ( Long_Float'Asm_Output("=m", Result ) ), 
         Inputs  => ( Long_Float'Asm_Input ( "m",      x ) ) ); 
    return Result; 
  end Sqrt; 

You can do the same thing for trig functions...  Just cut and past and see if this example works. 

Cheers 

  reply	other threads:[~2018-09-17 22:41 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-17  2:22 GNAT for AVR - Mathematical Functions ada.newcomer
2018-09-17  7:18 ` Dmitry A. Kazakov
2018-09-17 22:41   ` Aurele Vitali [this message]
2018-09-17 12:22 ` Simon Wright
2018-09-17 17:28 ` Bill Findlay
2018-09-17 22:35 ` Aurele Vitali
2018-09-18  1:16 ` rakusu_klein
2018-09-25  7:14 ` R R
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox