Trabb Pardo–Knuth algorithm: Difference between revisions

Content added Content deleted
No edit summary
Line 1,467: Line 1,467:
f(-3) = -133.2679491924311
f(-3) = -133.2679491924311
f(-5) = -622.7639320225002</pre>
f(-5) = -622.7639320225002</pre>



=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">
// 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
</syntaxhighlight>
{{output}}
<pre>
Please enter 11 numbers:
f(4.3010) = 399.8863
f(4.3020) = [Overflow]
f(4.3030) = [Overflow]
f(4.3050) = [Overflow]
f(4.3000) = 399.6086
f(4.0000) = 322.0000
f(3.0000) = 136.7321
f(2.0000) = 41.4142
f(1.0000) = 6.0000
f(-1.0000) = -4.0000
f(10.0000) = [Overflow]
</pre>



=={{header|Go}}==
=={{header|Go}}==