Data update

This commit is contained in:
Ingy döt Net 2026-02-01 16:33:20 -08:00
parent 5150844a7d
commit 4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions

View file

@ -1,27 +0,0 @@
with Ada.Text_IO; use Ada.Text_IO;
procedure Test_Nth_Root is
generic
type Real is digits <>;
function Nth_Root (Value : Real; N : Positive) return Real;
function Nth_Root (Value : Real; N : Positive) return Real is
type Index is mod 2;
X : array (Index) of Real := (Value, Value);
K : Index := 0;
begin
loop
X (K + 1) := ( (Real (N) - 1.0) * X (K) + Value / X (K) ** (N-1) ) / Real (N);
exit when X (K + 1) >= X (K);
K := K + 1;
end loop;
return X (K + 1);
end Nth_Root;
function Long_Nth_Root is new Nth_Root (Long_Float);
begin
Put_Line ("1024.0 10th =" & Long_Float'Image (Long_Nth_Root (1024.0, 10)));
Put_Line (" 27.0 3rd =" & Long_Float'Image (Long_Nth_Root (27.0, 3)));
Put_Line (" 2.0 2nd =" & Long_Float'Image (Long_Nth_Root (2.0, 2)));
Put_Line ("5642.0 125th =" & Long_Float'Image (Long_Nth_Root (5642.0, 125)));
end Test_Nth_Root;

View file

@ -1,26 +0,0 @@
;AutoIt Version: 3.2.10.0
$A=4913
$n=3
$x=20
ConsoleWrite ($n& " root of "& $A & " is " &nth_root_it($A,$n,$x))
ConsoleWrite ($n& " root of "& $A & " is " &nth_root_rec($A,$n,$x))
;Iterative
Func nth_root_it($A,$n,$x)
$x0="0"
While StringCompare(string($x0),string($x))
ConsoleWrite ($x&@CRLF)
$x0=$x
$x=((($n-1)*$x)+($A/$x^($n-1)))/$n
WEnd
Return $x
EndFunc
;Recursive
Func nth_root_rec($A,$n,$x)
ConsoleWrite ($x&@CRLF)
If $x==((($n-1)*$x)+($A/$x^($n-1)))/$n Then
Return $x
EndIf
Return nth_root_rec($A,$n,((($n-1)*$x)+($A/$x^($n-1)))/$n)
EndFunc

View file

@ -1,98 +0,0 @@
IDENTIFICATION DIVISION.
PROGRAM-ID. Nth-Root.
AUTHOR. Bill Gunshannon.
INSTALLATION.
DATE-WRITTEN. 4 Feb 2020.
************************************************************
** Program Abstract:
** Compute the Nth Root of a positive real number.
**
** Takes values from console. If Precision is left
** blank defaults to 0.001.
**
** Enter 0 for first value to terminate program.
************************************************************
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT Root-File ASSIGN TO "Root-File"
ORGANIZATION IS LINE SEQUENTIAL.
DATA DIVISION.
FILE SECTION.
FD Root-File
DATA RECORD IS Parameters.
01 Parameters.
05 Root PIC 9(5).
05 Num PIC 9(5)V9(5).
05 Precision PIC 9V9(9).
WORKING-STORAGE SECTION.
01 TEMP0 PIC 9(9)V9(9).
01 TEMP1 PIC 9(9)V9(9).
01 RESULTS.
05 Field1 PIC ZZZZZ.ZZZZZ.
05 FILLER PIC X(5).
05 Field2 PIC ZZZZ9.
05 FILLER PIC X(14).
05 Field3 PIC 9.999999999.
01 HEADER.
05 FILLER PIC X(72)
VALUE " Number Root Precision.".
01 Disp-Root PIC ZZZZZ.ZZZZZ.
PROCEDURE DIVISION.
Main-Program.
PERFORM FOREVER
PERFORM Get-Input
IF Precision = 0.0
THEN MOVE 0.001 to Precision
END-IF
PERFORM Compute-Root
MOVE Root TO Field2
MOVE Num TO Field1
MOVE Precision TO Field3
DISPLAY HEADER
DISPLAY RESULTS
DISPLAY " "
MOVE TEMP1 TO Disp-Root
DISPLAY "The Root is: " Disp-Root
END-PERFORM.
Get-Input.
DISPLAY "Input Base Number: " WITH NO ADVANCING
ACCEPT Num
IF Num EQUALS ZERO
THEN
DISPLAY "Good Bye."
STOP RUN
END-IF
DISPLAY "Input Root: " WITH NO ADVANCING
ACCEPT Root
DISPLAY "Input Desired Precision: " WITH NO ADVANCING
ACCEPT Precision.
Compute-Root.
MOVE Root TO TEMP0
DIVIDE Num BY Root GIVING TEMP1
PERFORM UNTIL FUNCTION ABS(TEMP0 - TEMP1)
LESS THAN Precision
MOVE TEMP1 TO TEMP0
COMPUTE TEMP1 = (( Root - 1.0) * TEMP1 + Num /
TEMP1 ** (Root - 1.0)) / Root
END-PERFORM.
END-PROGRAM.

View file

@ -1,39 +0,0 @@
#NoTeS: This sample code does not validate inputs
# Thus, if there are errors the 'scary' red-text
# error messages will appear.
#
# This code will not work properly in floating point values of n,
# and negative values of A.
#
# Supports negative values of n by reciprocating the root.
$epsilon=1E-10 #Sample Epsilon (Precision)
function power($x,$e){ #As I said in the comment
$ret=1
for($i=1;$i -le $e;$i++){
$ret*=$x
}
return $ret
}
function root($y,$n){ #The main Function
if (0+$n -lt 0){$tmp=-$n} else {$tmp=$n} #This checks if n is negative.
$ans=1
do{
$d = ($y/(power $ans ($tmp-1)) - $ans)/$tmp
$ans+=$d
} while ($d -lt -$epsilon -or $d -gt $epsilon)
if (0+$n -lt 0){return 1/$ans} else {return $ans}
}
#Sample Inputs
root 625 2
root 2401 4
root 2 -2
root 1.23456789E-20 34
root 9.87654321E20 10 #Quite slow here, I admit...
((root 5 2)+1)/2 #Extra: Computes the golden ratio
((root 5 2)-1)/2

View file

@ -1,5 +1,5 @@
-- 8 May 2025
include Settings
-- 24 Aug 2025
include Setting
say 'NTH ROOT'
say version
@ -18,7 +18,4 @@ say 'digits = ' digs
say 'answer = ' Nroot(x,root)
exit
include Numbers
include Functions
include Constants
include Abend
include Math