changeset 812:eaf0a0d20b60

Walter <walter@digitalmars.com> 2006-01-29 mail:002601c62518$68a870b0$0400a8c0@colossus
author thomask
date Sun, 05 Feb 2006 09:58:23 +0000
parents 47da30a67c8d
children c4c154735ebb
files run/double_22.d run/float_22.d
diffstat 2 files changed, 32 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/run/double_22.d	Sun Feb 05 09:57:55 2006 +0000
+++ b/run/double_22.d	Sun Feb 05 09:58:23 2006 +0000
@@ -6,11 +6,25 @@
 // @date@	2005-04-02
 // @uri@	news:5efpfwr0e1l5$.ks45nx0xz2zf$.dlg@40tude.net
 
+// For floating point operations and expression intermediate values,
+// a greater precision can be used than the type of the expression.
+// Only the minimum precision is set by the types of the operands,
+// not the maximum.
+ 
 module dstress.run.double_22;
 
 int main(){
 	double f = 0.0000195;
 	assert(typeid(typeof(0.0000195)) == typeid(double));
-	assert(.5 + f * 1e6 == .5 + 0.0000195 * 1e6);
-	return 0;
+
+	real diff = (0.5 + f * 1e6) - (0.5 + 0.0000195 * 1e6);
+
+
+	if(diff < 0){
+		diff *= -1;
+	}
+
+	if(diff < double.epsilon * 8){
+		return 0;
+	}
 }
--- a/run/float_22.d	Sun Feb 05 09:57:55 2006 +0000
+++ b/run/float_22.d	Sun Feb 05 09:58:23 2006 +0000
@@ -6,11 +6,25 @@
 // @date@	2005-04-02
 // @uri@	news:5efpfwr0e1l5$.ks45nx0xz2zf$.dlg@40tude.net
 
+// For floating point operations and expression intermediate values,
+// a greater precision can be used than the type of the expression.
+// Only the minimum precision is set by the types of the operands,
+// not the maximum.
+ 
 module dstress.run.float_22;
 
 int main(){
 	float f = 0.0000195f;
 	assert(typeid(typeof(0.0000195f)) == typeid(float));
-	assert(.5f + f * 1e6f == .5f + 0.0000195f * 1e6f);
-	return 0;
+
+	real diff = (0.5f + f * 1e6f) - (0.5f + 0.0000195f * 1e6f);
+
+
+	if(diff < 0){
+		diff *= -1;
+	}
+
+	if(diff < float.epsilon * 8){
+		return 0;
+	}
 }