Created
July 1, 2014 15:04
-
-
Save helgee/f179b9610aa104e38966 to your computer and use it in GitHub Desktop.
Floating Point Error
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <math.h> | |
double f(double t, double y) { | |
return y*cos(t); | |
} | |
int main() { | |
double yjulia = 2.31111366572489; | |
double yfortr = 2.3111136657248901; | |
double t = 0.7012954297850128; | |
double c7 = 0.25; | |
double h = 1.1672276724655861; | |
printf("%20.16f\n", f(t+c7*h, yfortr)); | |
printf("%20.16f\n", f(t+c7*h, yjulia)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
program test | |
implicit none | |
double precision :: yjulia | |
double precision :: yfortran | |
double precision :: t | |
double precision :: c7 | |
double precision :: h | |
yjulia = 2.31111366572489d0 | |
yfortr = 2.3111136657248901d0 | |
t = 0.7012954297850128d0 | |
c7 = 0.25d0 | |
h = 1.1672276724655861d0 | |
print *, f(t+c7*h, yfortr) | |
print *, f(t+c7*h, yjulia) | |
contains | |
double precision function f(t,y) | |
double precision, intent(in) :: t | |
double precision, intent(in) :: y | |
f = y*cos(t) | |
end function | |
end program |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env julia -F | |
f(t,y) = y*cos(t) | |
t = 0.7012954297850128 | |
yjulia = 2.31111366572489 | |
yfortr = 2.3111136657248901 | |
c7 = 0.25 | |
h = 1.1672276724655861 | |
println(f(t+c7*h, yfortr)) | |
println(f(t+c7*h, yjulia)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python | |
from __future__ import print_function | |
import math | |
def f(t,y): | |
return y*math.cos(t) | |
t = 0.7012954297850128 | |
yjulia = 2.31111366572489 | |
yfortr = 2.3111136657248901 | |
c7 = 0.25 | |
h = 1.1672276724655861 | |
print(repr(f(t+c7*h, yfortr))) | |
print(repr(f(t+c7*h, yjulia))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment