numerics

What's the future of std::valarray look like?

家住魔仙堡 提交于 2019-12-12 08:17:29
问题 Up until fairly recently I hadn't been keeping up with the C++11 deliberations. As I try to become more familiar with it and the issues being worked, I came across this site which seems to be advocating for deprecating or removing std::valarray since most people are using Blitz++ instead. I guess I'm probably one of the few people out there who still uses std::valarray (and yes I know the class has a sordid past, a tarnished present, and a questionable future). But, it does what I need, and

Take the average of two signed numbers in C

风格不统一 提交于 2019-12-05 15:28:42
问题 Let us say we have x and y and both are signed integers in C, how do we find the most accurate mean value between the two? I would prefer a solution that does not take advantage of any machine/compiler/toolchain specific workings. The best I have come up with is: (a / 2) + (b / 2) + !!(a % 2) * !!(b %2) Is there a solution that is more accurate? Faster? Simpler? What if we know if one is larger than the other a priori? Thanks. D Editor's Note : Please note that the OP expects answers that are

Take the average of two signed numbers in C

拜拜、爱过 提交于 2019-12-04 01:21:16
Let us say we have x and y and both are signed integers in C, how do we find the most accurate mean value between the two? I would prefer a solution that does not take advantage of any machine/compiler/toolchain specific workings. The best I have come up with is: (a / 2) + (b / 2) + !!(a % 2) * !!(b %2) Is there a solution that is more accurate? Faster? Simpler? What if we know if one is larger than the other a priori? Thanks. D Editor's Note : Please note that the OP expects answers that are not subject to integer overflow when input values are close to the maximum absolute bounds of the C

What's the future of std::valarray look like?

邮差的信 提交于 2019-12-03 22:08:59
Up until fairly recently I hadn't been keeping up with the C++11 deliberations. As I try to become more familiar with it and the issues being worked, I came across this site which seems to be advocating for deprecating or removing std::valarray since most people are using Blitz++ instead. I guess I'm probably one of the few people out there who still uses std::valarray (and yes I know the class has a sordid past, a tarnished present, and a questionable future). But, it does what I need, and perhaps more important, it's part of the standard (for now any way). Aside from the one site above, I've