Pure Programmer
Blue Matrix


Cluster Map

Project: Renard Numbers with Rounding Function

Modify the program that computes Renard numbers. Modify it so that the values stored in the array of Renard numbers are rounded instead of using formetted output to round the output used in the original solution.

The roundSigDig() function should take the floating point value to round and the number of significant digits to keep (precision). It should return a new floating point value rounded to the number of significant digits. For example 1234 rounded to two significant digits is 1200 This rounding can be accomplished by multiplying the value (n) by 10int(precision-log10(n)-1), adding 0.5, computing the integer floor, then dividing by 10int(precision-log10(n)-1) again.

See project RenardNumbers1 and [[Significant Figures]]

Output
$ node RenardNumbers2.js 5 1 R5: 1, 2, 3, 4, 6, 10, 20, 30, 40, 60, 100, 200, 300, 400, 600, 1000 $ node RenardNumbers2.js 5 2 R5: 1, 1.6, 2.5, 4, 6.3, 10, 16, 25, 40, 63, 100, 160, 250, 400, 630, 1000 $ node RenardNumbers2.js 10 2 R10: 1, 1.3, 1.6, 2, 2.5, 3.2, 4, 5, 6.3, 7.9, 10, 13, 16, 20, 25, 32, 40, 50, 63, 79, 100, 130, 160, 200, 250, 320, 400, 500, 630, 790, 1000 $ node RenardNumbers2.js 20 2 R20: 1, 1.1, 1.3, 1.4, 1.6, 1.8, 2, 2.2, 2.5, 2.8, 3.2, 3.5, 4, 4.5, 5, 5.6, 6.3, 7.1, 7.9, 8.9, 10, 11, 13, 14, 16, 18, 20, 22, 25, 28, 32, 35, 40, 45, 50, 56, 63, 71, 79, 89, 100, 110.00000000000001, 130, 140, 160, 180, 200, 220.00000000000003, 250, 280, 320, 350, 400, 450, 500, 560, 630, 710, 790, 890, 1000 $ node RenardNumbers2.js 40 3 R40: 1, 1.06, 1.12, 1.19, 1.26, 1.33, 1.41, 1.5, 1.58, 1.68, 1.78, 1.88, 2, 2.11, 2.24, 2.37, 2.51, 2.66, 2.82, 2.99, 3.16, 3.35, 3.55, 3.76, 3.98, 4.22, 4.47, 4.73, 5.01, 5.31, 5.62, 5.96, 6.31, 6.68, 7.08, 7.5, 7.94, 8.41, 8.91, 9.44, 10, 10.600000000000001, 11.200000000000001, 11.899999999999999, 12.6, 13.3, 14.1, 15, 15.8, 16.8, 17.8, 18.799999999999997, 20, 21.099999999999998, 22.400000000000002, 23.700000000000003, 25.099999999999998, 26.6, 28.2, 29.900000000000002, 31.6, 33.5, 35.5, 37.599999999999994, 39.8, 42.199999999999996, 44.699999999999996, 47.300000000000004, 50.099999999999994, 53.099999999999994, 56.2, 59.6, 63.099999999999994, 66.8, 70.8, 75, 79.4, 84.1, 89.1, 94.39999999999999, 100, 106, 112.00000000000001, 119, 126, 133, 141, 150, 158, 168, 178, 188, 200, 211, 224.00000000000003, 237, 250.99999999999997, 266, 282, 299, 316, 335, 355, 376, 398, 422, 447, 473.00000000000006, 501, 531, 562, 596, 631, 668, 708, 750, 794, 841, 891, 944, 1000

Solution