(*
/*

CLASS {NATIVE_Mathematics|_Delphi},
NATIVE, ABSTRACT :

NATIVE: "///COPY NATIVE_Mathematics.pas" .

*/
*)

unit NATIVE_Mathematics;

{$I AL4_options.inc}

interface 

uses
	 {$IFDEF LINUX}{$ELSE}
		Windows,
	 {$ENDIF}
	 {$IFDEF KOL}KOLMath, KOL
	 {$ELSE}
	 	Math, SysUtils
	 {$ENDIF};



{$IFnDEF _D6orHigher}

function IsInfinite(const AValue: Double): Boolean;

{$ENDIF}



implementation

{$IFnDEF _D6orHigher}
function IsInfinite(const AValue: Double): Boolean;
{$IFnDEF _D5orHigher}
type Td64 = record lo, hi: DWORD; end;
	 Pd64 = ^Td64;
var v: Td64; 
{$ENDIF}
begin
	{$IFDEF _D5orHigher}
		Result := ((PInt64(@AValue)^ and $7FF0000000000000) = $7FF0000000000000) 
			  and ((PInt64(@AValue)^ and $000FFFFFFFFFFFFF) = $0000000000000000);
	{$ELSE}
		v := Pd64(@AValue)^;
		Result := ((v.Hi and $7FF00000) = $7FF00000)
			and ((V.Hi and $000FFFFF) = 0) and (V.Lo = 0);
	{$ENDIF}
end;
{$ENDIF}



    (*
    /*
    // {Mathematics} native functions code:
    
    CONST STR :
        NATIVE_Mathematics_import = @
        "uses NATIVE_Mathematics,"
        "{$IFDEF LINUX}{$ELSE}"
        "		Windows, "
        "	  {$ENDIF} "
        "{$IFDEF KOL}KOLMath, "
        "{$ELSE}"
        "		Math, "
        "{$ENDIF} System_functions;"

        NATIVE_Power = @
        "	 if (X_B = 0) and (X_Exp < 0) "
        "		{$IFNDEF KOL} or IsInfinite(X_Exp) {$ENDIF} then"
        "		RESULT := NaN {_ division by zero _}"
        "    else "
        "	 try"     
        "		RESULT := Power(X_B, X_Exp);"
        "	 except"
        "		RESULT := NaN;"
        "	 end;"     

        NATIVE_Sqrt = @
        "    try"
        "		{$IFDEF FPC}"
        "		 if (X_X) < 0 then begin RESULT := NaN; Exit; end;"
        "		{$ENDIF}"
        "		{$IFDEF KOL}"
        "		 if (X_X) < 0 then begin RESULT := NaN; Exit; end;"
        "		{$ENDIF}"
        "        RESULT := Sqrt(X_X);"
        "    except {$IFNDEF NOERR} on E: Exception do {$ENDIF} begin"
        "        {$IFNDEF NOERR} Any_exception(E); {$ENDIF}"
        "        Result := NaN; end;"
        "    end;"

        NATIVE_Is_NAN = @
        "    RESULT := IsNAN(X_V);"

        NATIVE_Is_INF = @
        "{$IFDEF KOL}{$IFnDEF _D5orHigher}var ii: I64; {$ENDIF}{$ENDIF} "
        "var d: Double;"
        "	 d := X_V;"
        "    {$IFDEF KOL}"
        "		{$IFDEF _D5orHigher}"     
        "    RESULT := (( PInt64(@d)^ and $7FF0000000000000) = "
        "               $7FF0000000000000) and"
        "              (( PInt64(@d)^ and $000FFFFFFFFFFFFF) = "
        "               $0000000000000000);"
    	"		{$ELSE}"
    	"			ii := PInt64(@d)^;"
    	"			RESULT := ((ii.Hi and $7FF00000) = $7FF00000)"
    	"			and ((ii.Hi and $000FFFFF) = 0)"
    	"			and (ii.Lo = 0);"     
    	"		{$ENDIF}"     
        "    {$ELSE}"
        "    RESULT := IsInfinite(d);"
        "    {$ENDIF}"

        NATIVE_Abs = @
        "    RESULT := Abs(X_X);"

        NATIVE_Round = @
        "   Result := Round(X_X);"

        NATIVE_Trunc = @
        "   Result := Trunc(X_X);"

        NATIVE_Log10 = @
        "    try"
        "        Result := Log10(X_X);"
        "    except {$IFNDEF NOERR} on E: Exception do {$ENDIF} begin"
        "        {$IFNDEF NOERR} Any_exception(E); {$ENDIF}"
        "        Result := NaN; end;"
        "    end;"

        NATIVE_Ln = @
        "    try"
        "		 if X_X <= 0 then Result := NaN"
        "		 else if X_X >= 1 then Result := Ln(X_X)"
        "        else Result := LnXP1(X_X - 1);"
        "    except {$IFNDEF NOERR} on E: Exception do {$ENDIF} begin"
        "        {$IFNDEF NOERR} Any_exception(E); {$ENDIF}"
        "        Result := NaN; end;"
        "    end;"

        NATIVE_Base_log = @
        "    try "
        "        Result := LnXP1(X_X - 1) / LnXP1(X_Base - 1);"
        "    except {$IFNDEF NOERR} on E: Exception do {$ENDIF} begin"
        "        {$IFNDEF NOERR} Any_exception(E); {$ENDIF}"
        "        Result := NaN; end;"
        "    end;"

        NATIVE_PI = @
        "    RESULT := PI;"

        NATIVE_Sin = @
        "    try"
        "        RESULT := Sin(X_X);"
        "    except {$IFNDEF NOERR} on E: Exception do {$ENDIF} begin"
        "        {$IFNDEF NOERR} Any_exception(E); {$ENDIF}"
        "        Result := NaN; end;"
        "    end;"

        NATIVE_Cos = @
        "    try"
        "        RESULT := Cos(X_X);"
        "    except {$IFNDEF NOERR} on E: Exception do {$ENDIF} begin"
        "        {$IFNDEF NOERR} Any_exception(E); {$ENDIF}"
        "        Result := NaN; end;"
        "    end;"

        NATIVE_Tan = @
        "    try"
        "        RESULT := Tan(X_X);"
        "    except {$IFNDEF NOERR} on E: Exception do {$ENDIF} begin"
        "        {$IFNDEF NOERR} Any_exception(E); {$ENDIF}"
        "        Result := NaN; end;"
        "    end;"

        NATIVE_Cotan = @
        "    try"
        "        RESULT := Cotan(X_X);"
        "    except {$IFNDEF NOERR} on E: Exception do {$ENDIF} begin"
        "        {$IFNDEF NOERR} Any_exception(E); {$ENDIF}"
        "        Result := NaN; end;"
        "    end;"

        NATIVE_Arcsin = @"    try"
        "        RESULT := ArcSin(X_X);"
        "    except {$IFNDEF NOERR} on E: Exception do {$ENDIF} begin"
        "        {$IFNDEF NOERR} Any_exception(E); {$ENDIF}"
        "        Result := NaN; end;"
        "    end;"

        NATIVE_Arccos = @
        "    try"
        "        RESULT := ArcCos(X_X);"
        "    except {$IFNDEF NOERR} on E: Exception do {$ENDIF} begin"
        "        {$IFNDEF NOERR} Any_exception(E); {$ENDIF}"
        "        Result := NaN; end;"
        "    end;"

        NATIVE_Arctan = @
        "    try"
        "        RESULT := ArcTan(X_X);"
        "    except {$IFNDEF NOERR} on E: Exception do {$ENDIF} begin"
        "        {$IFNDEF NOERR} Any_exception(E); {$ENDIF}"
        "        Result := NaN; end;"
        "    end;"

        NATIVE_Arctan2 = @
        "    try"
        "        RESULT := ArcTan2(X_Y, X_X);"
        "    except {$IFNDEF NOERR} on E: Exception do {$ENDIF} begin"
        "        {$IFNDEF NOERR} Any_exception(E); {$ENDIF}"
        "        Result := NaN; end;"
        "    end;"

        NATIVE_Exp = @
        "    try"
        "        RESULT := Exp(X_X);"
        "    except {$IFNDEF NOERR} on E: Exception do {$ENDIF} begin"
        "        {$IFNDEF NOERR} Any_exception(E); {$ENDIF}"
        "        Result := NaN; end;"
        "    end;"

        NATIVE_Sinh = @
        "    try"
        "        RESULT := Sinh(X_X);"
        "    except {$IFNDEF NOERR} on E: Exception do {$ENDIF} begin"
        "        {$IFNDEF NOERR} Any_exception(E); {$ENDIF}"
        "        Result := NaN; end;"
        "    end;"

        NATIVE_Cosh = @
        "    try"
        "        RESULT := Cosh(X_X);"
        "    except {$IFNDEF NOERR} on E: Exception do {$ENDIF} begin"
        "        {$IFNDEF NOERR} Any_exception(E); {$ENDIF}"
        "        Result := NaN; end;"
        "    end;"

        NATIVE_Tanh = @
        "    try"
        "        RESULT := Tanh(X_X);"
        "    except {$IFNDEF NOERR} on E: Exception do {$ENDIF} begin"
        "        {$IFNDEF NOERR} Any_exception(E); {$ENDIF}"
        "        Result := NaN; end;"
        "    end;"

        NATIVE_Coth = @
        "    try"
        "		{$IFDEF FPC}"
        "        RESULT := 1.0 / TanH(X_X);"
        "		 {$DEFINE coth_calculated}"
        "		{$ENDIF}"
        "       {$IFDEF KOL}"
        "        RESULT := 1.0 / TanH(X_X);"
        "		 {$DEFINE coth_calculated}"
        "		{$ENDIF}"
        "       {$IFnDEF _D6orHigher}"
        "        RESULT := 1.0 / TanH(X_X);"
        "		 {$DEFINE coth_calculated}"
        "		{$ENDIF}"
        "       {$IFNDEF coth_calculated}"
        "        RESULT := Coth(X_X);"
        "       {$ENDIF}"
        "    except {$IFNDEF NOERR} on E: Exception do {$ENDIF} begin"
        "        {$IFNDEF NOERR} Any_exception(E); {$ENDIF}"
        "        Result := NaN; end;"
        "    end;"

        NATIVE_Arcsinh = @
        "    try"
        "        RESULT := ArcSinh(X_X);"
        "    except {$IFNDEF NOERR} on E: Exception do {$ENDIF} begin"
        "        {$IFNDEF NOERR} Any_exception(E); {$ENDIF}"
        "        Result := NaN; end;"
        "    end;"

        NATIVE_Arccosh = @
        "    try"
        "        RESULT := ArcCosh(X_X);"
        "    except {$IFNDEF NOERR} on E: Exception do {$ENDIF} begin"
        "        {$IFNDEF NOERR} Any_exception(E); {$ENDIF}"
        "        Result := NaN; end;"
        "    end;"

        NATIVE_Arctanh = @
        "    try"
        "        RESULT := ArcTanh(X_X);"
        "    except {$IFNDEF NOERR} on E: Exception do {$ENDIF} begin"
        "        {$IFNDEF NOERR} Any_exception(E); {$ENDIF}"
        "        Result := NaN; end;"
        "    end;"

        .
        
*/
*)

end .

(*
/*
END
*/
*)

