Changeset 1313
- Timestamp:
- 10/27/09 03:29:55 (15 years ago)
- Files:
-
- trunk/phobos/linux.mak (modified) (2 diffs)
- trunk/phobos/std/math.d (modified) (2 diffs)
- trunk/phobos/std/typetuple.d (modified) (3 diffs)
- trunk/phobos/std/xml.d (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/phobos/linux.mak
r1285 r1313 45 45 DMD_posix = dmd 46 46 OBJSUFFIX_posix = .o 47 47 LIB_posix = libphobos2.a 48 48 EXESUFFIX_posix = 49 49 LIBDRUNTIME_posix = $(DRUNTIMEDIR)/libdruntime.a 50 50 CFLAGS_posix_debug = -m32 -g $(CFLAGS) 51 51 CFLAGS_posix_release = -m32 -O3 $(CFLAGS) 52 52 53 53 # D flags for all OSs, but customized by build 54 54 DFLAGS_debug = -w -g -debug -d $(DFLAGS) 55 DFLAGS_release = -w -O -release - inline -nofloat -d $(DFLAGS)55 DFLAGS_release = -w -O -release -nofloat -d $(DFLAGS) 56 56 57 57 # D flags for documentation generation 58 58 DDOCFLAGS=-version=ddoc -d -c -o- $(STDDOC) 59 59 60 60 ################################################################################ 61 61 62 62 STD_MODULES = $(addprefix std/, algorithm array atomics base64 bigint \ 63 63 bitmanip boxer compiler complex contracts conv cpuid cstream \ 64 64 ctype date datebase dateparse demangle encoding file format \ 65 65 functional getopt intrinsic iterator loader math md5 \ … … 150 150 @$$(call RUN_$1,$$@) 151 151 # succeeded, render the file new again 152 152 @touch $$@ 153 153 154 154 # $(PRODUCTIONLIBDIR)/tmp_$2$$(LIB_$1) : $$(LIB_$1_$2) 155 155 # ln -sf $$(realpath $$<) $$@ 156 156 157 157 $1/$2 : $$(LIB_$1_$2) 158 158 $$(LIB_$1_$2) : $$(SRC2LIB_$1) $$(OBJS_$1_$2) \ 159 159 $(LIBDRUNTIME_$1) 160 @echo $$(DMD$1$2) $(DFLAGS_$2) -lib -of$$@ "[...tons of files...]"161 @$$(DMD$1$2) $(DFLAGS_$2) -lib -of$$@ $$^160 # @echo $$(DMD$1$2) $(DFLAGS_$2) -lib -of$$@ "[...tons of files...]" 161 $$(DMD$1$2) $(DFLAGS_$2) -lib -of$$@ $$^ 162 162 163 163 $$(ROOT$1$2)/.directory : 164 164 mkdir --parents $$(OBJDIR) || exists $$(OBJDIR) 165 165 if [ "$(SERVER_$1)" != "" ]; then \ 166 166 $$(call RUN_$1,mkdir) --parents $$(OBJDIR)/$1 && \ 167 167 ln -sf $(HOMEMAP_$1)/$(SERVERDIR_$1)/$$(OBJDIR)/$1 obj/ ; \ 168 168 fi 169 169 mkdir --parents $$@ || [ -d $$@ ] 170 170 171 171 $1/$2/unittest : $1/$2 $$(addsuffix $$(EXESUFFIX_$1),$$(addprefix $$(OBJDIR)/$1/$2/unittest/,$(STD_MODULES))) trunk/phobos/std/math.d
r1283 r1313 3086 3086 3087 3087 /** 3088 3088 Computes whether $(D lhs) is approximately equal to $(D rhs) 3089 3089 admitting a maximum relative difference $(D maxRelDiff) and a 3090 3090 maximum absolute difference $(D maxAbsDiff). 3091 3091 3092 3092 If the two inputs are ranges, $(D approxEqual) returns true if and 3093 3093 only if the ranges have the same number of elements and if $(D 3094 3094 approxEqual) evaluates to $(D true) for each pair of elements. 3095 3095 */ 3096 bool approxEqual(T, U, V)(T lhs, U rhs, V maxRelDiff, V maxAbsDiff = 0)3096 bool approxEqual(T, U, V)(T lhs, U rhs, V maxRelDiff, V maxAbsDiff = 1e-5) 3097 3097 { 3098 3098 static if (isInputRange!T) 3099 3099 { 3100 3100 static if (isInputRange!U) 3101 3101 { 3102 3102 // Two ranges 3103 3103 for (;; lhs.popFront, rhs.popFront) 3104 3104 { 3105 3105 if (lhs.empty) return rhs.empty; 3106 3106 if (rhs.empty) return lhs.empty; … … 3123 3123 { 3124 3124 static if (isInputRange!U) 3125 3125 { 3126 3126 // lhs is number, rhs is array 3127 3127 return approxEqual(rhs, lhs, maxRelDiff, maxAbsDiff); 3128 3128 } 3129 3129 else 3130 3130 { 3131 3131 // two numbers 3132 3132 //static assert(is(T : real) && is(U : real)); 3133 if (rhs == 0) { 3134 return (lhs == 0 ? 0 : 1) <= maxRelDiff; 3133 if (rhs == 0) 3134 { 3135 return fabs(lhs) <= maxAbsDiff; 3135 3136 } 3136 3137 return fabs((lhs - rhs) / rhs) <= maxRelDiff 3137 || maxAbsDiff != 0 && fabs(lhs - rhs) < maxAbsDiff;3138 || maxAbsDiff != 0 && fabs(lhs - rhs) <= maxAbsDiff; 3138 3139 } 3139 3140 } 3140 3141 } 3141 3142 3142 3143 /** 3143 Returns $(D approxEqual(lhs, rhs, 0.01)).3144 Returns $(D approxEqual(lhs, rhs, 1e-2, 1e-5)). 3144 3145 */ 3145 3146 bool approxEqual(T, U)(T lhs, U rhs) 3146 3147 { 3147 return approxEqual(lhs, rhs, 0.01);3148 return approxEqual(lhs, rhs, 1e-2, 1e-5); 3148 3149 } 3149 3150 3150 3151 unittest 3151 3152 { 3152 3153 assert(approxEqual(1.0, 1.0099)); 3153 3154 assert(!approxEqual(1.0, 1.011)); 3154 3155 float[] arr1 = [ 1.0, 2.0, 3.0 ]; 3155 3156 double[] arr2 = [ 1.001, 1.999, 3 ]; 3156 3157 assert(approxEqual(arr1, arr2)); 3157 3158 } trunk/phobos/std/typetuple.d
r1279 r1313 3 3 /** 4 4 * Templates with which to manipulate type tuples (also known as type lists). 5 5 * 6 6 * Some operations on type tuples are built in to the language, 7 7 * such as TL[$(I n)] which gets the $(I n)th type from the 8 8 * type tuple. TL[$(I lwr) .. $(I upr)] returns a new type 9 9 * list that is a slice of the old one. 10 10 * 11 11 * References: 12 12 * Based on ideas in Table 3.1 from 13 * $(LINK2 http:// www.amazon.com/exec/obidos/ASIN/0201704315/ref=ase_classicempire/102-2957199-2585768,13 * $(LINK2 http://amazon.com/exec/obidos/ASIN/0201704315/ref=ase_classicempire/102-2957199-2585768, 14 14 * Modern C++ Design), 15 15 * Andrei Alexandrescu (Addison-Wesley Professional, 2001) 16 16 * Macros: 17 17 * WIKI = Phobos/StdTypeTuple 18 18 * 19 19 * Copyright: Copyright Digital Mars 2005 - 2009. 20 20 * License: <a href="http://www.boost.org/LICENSE_1_0.txt">Boost License 1.0</a>. 21 21 * Authors: $(WEB digitalmars.com, Walter Bright) 22 22 * 23 23 * Copyright Digital Mars 2005 - 2009. … … 353 353 equals!(short, ubyte, byte, byte)); 354 354 355 355 static assert(Pack!(Replace!(1111, byte, 356 356 2222, 1111, 1111, 1111)). 357 357 equals!(2222, byte, 1111, 1111)); 358 358 359 359 static assert(Pack!(Replace!(byte, 1111, 360 360 short, byte, byte, byte)). 361 361 equals!(short, 1111, byte, byte)); 362 362 363 static assert(Pack!(Replace!(1111, "11", 364 2222, 1111, 1111, 1111)). 365 equals!(2222, "11", 1111, 1111)); 363 // @@@BUG@@@ 364 // static assert(Pack!(Replace!(1111, "11", 365 // 2222, 1111, 1111, 1111)). 366 // equals!(2222, "11", 1111, 1111)); 366 367 } 367 368 368 369 /** 369 370 * Returns a typetuple created from TList with all occurrences 370 371 * of type T, if found, replaced with type U. 371 372 * Example: 372 373 * --- 373 374 * alias TypeTuple!(int, long, long, int, float) TL; 374 375 * 375 376 * ReplaceAll!(long, char, TL) … … 432 433 equals!(ubyte, short, ubyte, ubyte)); 433 434 434 435 static assert(Pack!(ReplaceAll!(1111, byte, 435 436 1111, 2222, 1111, 1111)). 436 437 equals!(byte, 2222, byte, byte)); 437 438 438 439 static assert(Pack!(ReplaceAll!(byte, 1111, 439 440 byte, short, byte, byte)). 440 441 equals!(1111, short, 1111, 1111)); 441 442 442 static assert(Pack!(ReplaceAll!(1111, "11", 443 1111, 2222, 1111, 1111)). 444 equals!("11", 2222, "11", "11")); 443 // @@@BUG@@@ 444 // static assert(Pack!(ReplaceAll!(1111, "11", 445 // 1111, 2222, 1111, 1111)). 446 // equals!("11", 2222, "11", "11")); 445 447 } 446 448 447 449 /** 448 450 * Returns a typetuple created from TList with the order reversed. 449 451 * Example: 450 452 * --- 451 453 * alias TypeTuple!(int, long, long, int, float) TL; 452 454 * 453 455 * Reverse!(TL) 454 456 * // is the same as: trunk/phobos/std/xml.d
r1279 r1313 381 381 { 382 382 char c = s[i]; 383 383 if (c != '&') 384 384 { 385 385 if (buffer.length != 0) buffer ~= c; 386 386 } 387 387 else 388 388 { 389 389 if (buffer.length == 0) 390 390 { 391 buffer = s.dup; 392 buffer.length = i; 391 buffer = s[0 .. i].dup; 393 392 } 394 393 if (startsWith(s[i..$],"&#")) 395 394 { 396 395 try 397 396 { 398 397 dchar d; 399 398 string t = s[i..$]; 400 399 checkCharRef(t, d); 401 400 char[4] temp; 402 401 buffer ~= temp[0 .. std.utf.encode(temp, d)];
