30 lines
616 B
Plaintext
30 lines
616 B
Plaintext
// Trabb Pardo-Knuth algorithm
|
|
|
|
include "NSLog.incl"
|
|
|
|
local fn f( x as double ) as double
|
|
end fn = fn pow( abs(x), 0.5) + 5 * ( fn pow(x, 3) )
|
|
|
|
void local fn PardoKnuth( userInput as double )
|
|
double x = userInput
|
|
double y = fn f(x)
|
|
NSLog( @"f(%.4f)\t= \b", x )
|
|
if( y < 400.0 )
|
|
NSLog( @"%.4f", y )
|
|
else
|
|
NSLog( @"[Overflow]" )
|
|
end if
|
|
end fn
|
|
|
|
NSUInteger i
|
|
CFArrayRef numbers
|
|
|
|
numbers = @[@10, @-1, @1, @2, @3 ,@4, @4.3, @4.305, @4.303, @4.302, @4.301]
|
|
|
|
NSLog( @"Please enter 11 numbers:" )
|
|
for i = len(numbers) to 1 step -1
|
|
fn PardoKnuth( fn NumberDoubleValue( numbers[i-1] ) )
|
|
next
|
|
|
|
HandleEvents
|