From: Warren on
John B. Matthews expounded in news:nospam-803846.13501829062010
@news.aioe.org:

> In article <Xns9DA683A562C67WarrensBlatherings(a)81.169.183.62>,
> Warren <ve3wwg(a)gmail.com> wrote:
>
>> One thing that really irks me (in lack of convenience)
>> is the lack of certain functions in the library support.
>> For example, I was looking for the inverse of a complex
>> number function. Did I missed it? My googling didn't
>> turn up much, nor did grep on the package hdrs.
>>
>> So because it is missing (AFIK), I had to google it and
>> figure out how it is done and code it myself. Wouldn't it
>> be safer if the function was already provided and tested?
>> Wouldn't it also be more accurately coded (floating
>> point can be tricky)? At least it would be tested.
>>
>> IIRC, I ran into the similar issues with some other
>> functions (ATAN2??). The LOG10() issue was
>> resolved when I discovered there is a base argument
>> in LOG(), so that was just my own "user error".
>>
>> But even if a function is considered "trivial", I
>> think it would be "safer" to include it. Additionally,
>> having them provided means that they will
>> be coded for the best accuracy.
>
> So, what is the "missing" function?
>
> <http://www.adaic.com/standards/05rm/html/RM-G-1-2.html>

1) The "inverse" of a complex number.

2) Also, math libraries usually include atan2(y,x),
since the error can be large with certain ranges
of x in the tan(x) form:

#include <math.h>

double atan2(double y, double x);
float atan2f(float y, float x);
long double atan2l(long double y, long double x);

Warren
From: Jeffrey R. Carter on
On 06/29/2010 12:31 PM, Warren wrote:
>
> 2) Also, math libraries usually include atan2(y,x),
> since the error can be large with certain ranges
> of x in the tan(x) form:

Ada.Numerics.Generic_Elementary_Functions defines

function Arctan (Y : Float_Type'Base;
X : Float_Type'Base := 1.0)
return Float_Type'Base;
function Arctan (Y : Float_Type'Base;
X : Float_Type'Base := 1.0;
Cycle : Float_Type'Base) return Float_Type'Base;

--
Jeff Carter
"Blessed is just about anyone with a vested interest in the status quo."
Monty Python's Life of Brian
73
From: Warren on
Jeffrey R. Carter expounded in news:i0djsr$632$1(a)tornado.tornevall.net:

> On 06/29/2010 12:31 PM, Warren wrote:
>>
>> 2) Also, math libraries usually include atan2(y,x),
>> since the error can be large with certain ranges
>> of x in the tan(x) form:
>
> Ada.Numerics.Generic_Elementary_Functions defines
>
> function Arctan (Y : Float_Type'Base;
> X : Float_Type'Base := 1.0)
> return
> Float_Type'Base;
> function Arctan (Y : Float_Type'Base;
> X : Float_Type'Base := 1.0;
> Cycle : Float_Type'Base) return
> Float_Type'Base;

Ok my bad, like the LOG10(), it is covered. But
I see no inverse of a complex number yet. ;-)

Warren
From: Adam Beneschan on
On Jun 29, 12:31 pm, Warren <ve3...(a)gmail.com> wrote:
>
> > So, what is the "missing" function?
>
> > <http://www.adaic.com/standards/05rm/html/RM-G-1-2.html>
>
> 1) The "inverse" of a complex number.

Isn't that just 1.0 / X? The division operator is defined in
Generic_Complex_Types and Complex_Types (G.1.1), and there is a
definition with a real left operand and complex right operand. If
there's a different kind of inverse, I'm not familiar with it. If
this is the same thing you're looking for, however, I don't see any
gain in providing a separate "Inverse" function. 1.0/X or X**(-1) are
readable enough for me.


> 2) Also, math libraries usually include atan2(y,x),
> since the error can be large with certain ranges
> of x in the tan(x) form:

As Jeffrey pointed out, Ada does have that. Since Ada allows
overloaded function names, we can still call it Arctan instead of
having to invent a name like atan2 (or three names as they do in C).
By the way, I'm not sure that the error is the main reason for having
this function. The result of the two-argument arctan function is in
the range -pi .. +pi, as opposed to -pi/2 .. +pi/2 for the one-
argument variation; this allows you to get a result in any of the four
quadrants (instead of just two), giving you the correct result when
you want to compute the angle corresponding to a point (x, y) on a
Cartesian graph.

-- Adam



> #include <math.h>
>
> double atan2(double y, double x);
> float atan2f(float y, float x);
> long double atan2l(long double y, long double x);
>
> Warren
From: Damien Carbonne on
Le 29/06/2010 21:31, Warren a �crit :
> 1) The "inverse" of a complex number.

Why don't you use 1.0 / Z ?
It is defined in Ada.Numerics.Generic_Complex_Types:

function "/" (Left : Real'Base; Right : Complex) return Complex;

Damien