Changeset 1953
- Timestamp:
- 09/04/10 14:34:11 (14 years ago)
- Files:
-
- trunk/docsrc/changelog.dd (modified) (1 diff)
- trunk/phobos/std/numeric.d (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/docsrc/changelog.dd
r1948 r1953 43 43 $(LI $(BUGZILLA 4381): Length attribute for std.typecons.Tuple.) 44 44 $(LI $(BUGZILLA 4387): std.range.Cycle assumes lvalue elements.) 45 45 $(LI $(BUGZILLA 4388): std.range.Radial assumes lvalue elements.) 46 46 $(LI $(BUGZILLA 4403): std.range.FrontTransversal assumes lvalue elements.) 47 47 $(LI $(BUGZILLA 4404): std.range.Transversal assumes lvalue elements.) 48 48 $(LI $(BUGZILLA 4455): Taking the sqrt of an integer shouldn't require an explicit cast.) 49 49 $(LI $(BUGZILLA 4464): std.range.take does not always return Take!R.) 50 50 $(LI $(BUGZILLA 4603): array(iota(1, 0)) error.) 51 51 $(LI $(BUGZILLA 4700): to!float("0") fails) 52 52 $(LI $(BUGZILLA 4789): std.algorithm.sort bug) 53 $(LI $(BUGZILLA 4810): dotProduct problem with ints) 53 54 ) 54 55 ) 55 56 56 57 57 58 <div id=version> 58 59 $(UL 59 60 $(NEW 049) 60 61 $(NEW 048) 61 62 $(NEW 047) 62 63 $(NEW 046) trunk/phobos/std/numeric.d
r1839 r1953 536 536 537 537 unittest 538 538 { 539 539 alias TypeTuple!( 540 540 CustomFloat!(5, 10), 541 541 CustomFloat!(5, 11, CustomFloatFlags.ieee ^ CustomFloatFlags.signed), 542 542 CustomFloat!(1, 15, CustomFloatFlags.ieee ^ CustomFloatFlags.signed), 543 543 CustomFloat!(4, 3, CustomFloatFlags.ieee | CustomFloatFlags.probability ^ CustomFloatFlags.signed) 544 544 545 545 ) FPTypes; 546 547 pragma(msg, " --- std.numeric(" ~ __LINE__.stringof ~ ") CustomFloat broken test ---");548 549 546 550 547 foreach (F; FPTypes) 551 548 { 552 549 auto x = F(0.125); 553 550 assert(x.get!float == 0.125F); 554 551 assert(x.get!double == 0.125); 555 552 556 553 x -= 0.0625; 557 554 assert(x.get!float == 0.0625F); 558 555 assert(x.get!double == 0.0625); … … 1236 1233 return result; 1237 1234 } 1238 1235 1239 1236 /// Ditto 1240 1237 Unqual!(CommonType!(F1, F2)) 1241 1238 dotProduct(F1, F2)(in F1[] avector, in F2[] bvector) 1242 1239 { 1243 1240 immutable n = avector.length; 1244 1241 assert(n == bvector.length); 1245 1242 auto avec = avector.ptr, bvec = bvector.ptr; 1246 typeof(return) sum0 = 0 .0, sum1 = 0.0;1243 typeof(return) sum0 = 0, sum1 = 0; 1247 1244 1248 1245 const all_endp = avec + n; 1249 1246 const smallblock_endp = avec + (n & ~3); 1250 1247 const bigblock_endp = avec + (n & ~15); 1251 1248 1252 1249 for (; avec != bigblock_endp; avec += 16, bvec += 16) 1253 1250 { 1254 1251 sum0 += avec[0] * bvec[0]; 1255 1252 sum1 += avec[1] * bvec[1]; 1256 1253 sum0 += avec[2] * bvec[2]; … … 1283 1280 sum0 += (*avec++) * (*bvec++); 1284 1281 1285 1282 return sum0; 1286 1283 } 1287 1284 1288 1285 unittest 1289 1286 { 1290 1287 double[] a = [ 1., 2., ]; 1291 1288 double[] b = [ 4., 6., ]; 1292 1289 assert(dotProduct(a, b) == 16); 1290 assert(dotProduct([1, 3, -5], [4, -2, -1]) == 3); 1293 1291 } 1294 1292 1295 1293 /** 1296 1294 Computes the $(LUCKY cosine similarity) of input ranges $(D a) and $(D 1297 1295 b). The two ranges must have the same length. If both ranges define 1298 1296 length, the check is done once; otherwise, it is done at each 1299 1297 iteration. If either range has all-zero elements, return 0. 1300 1298 */ 1301 1299 CommonType!(ElementType!(Range1), ElementType!(Range2)) 1302 1300 cosineSimilarity(Range1, Range2)(Range1 a, Range2 b)
