digitalmars.D - [your code here] Rounding real numbers
- Justin Whear (34/34) May 01 2015 A process for rounding numbers. This incarnation can be run like
- Andrei Alexandrescu (3/4) May 02 2015 Thanks Justin. Could someone take this? We don't have PHP code
- Vladimir Panteleev (4/8) May 02 2015 Doesn't need to be PHP, just show one example statically and
- Adam D. Ruppe (2/3) May 02 2015 could also be D
- Andrei Alexandrescu (2/5) May 02 2015 "code or it didn't happen" -- Andrei
- Andrei Alexandrescu (2/10) May 02 2015 That'd work. I gather you just volunteered :o). -- Andrei
- Vladimir Panteleev (2/16) May 04 2015 https://github.com/D-Programming-Language/dlang.org/pull/988
- Justin Whear (2/2) May 04 2015 Arrrg, formatting got torn up. Here's a Dpaste:
A process for rounding numbers. This incarnation can be run like round 1.23 3.4 4 or by reading lines from stdin. It could be simplified as an example by getting rid of the argument-processing form. It shows off templated function composition using std.functional.pipe, ct-regexes, and component programming. I wrote this after realizing that there wasn't a convenient UNIX utility for doing this and use it regularly. --------------------------------- import std.algorithm, std.conv, std.functional, std.math, std.regex, std.stdio; // Transforms input into a real number, rounds it, then to a string alias round = pipe!(to!real, lround, to!string); // Matches numbers that look like they need rounding static reFloatingPoint = ctRegex!`[0-9]+\.[0-9]+`; void main(string[] args) { // If arguments, process those and exit, otherwise wait around // for input on stdin if (args.length > 1) args[1..$].map!round.joiner(" ").writeln; else // Replace anything that looks like a real number with the // rounded equivalent. stdin.byLine(KeepTerminator.yes) .map!(l => l.replaceAll!(c => c.hit.round)(reFloatingPoint)) .copy(stdout.lockingTextWriter()); } ---------------------------------
May 01 2015
On Friday, 1 May 2015 at 17:17:09 UTC, Justin Whear wrote:A process for rounding numbers.Thanks Justin. Could someone take this? We don't have PHP code for rotating examples randomly yet. -- Andrei
May 02 2015
On Saturday, 2 May 2015 at 22:23:01 UTC, Andrei Alexandrescu wrote:On Friday, 1 May 2015 at 17:17:09 UTC, Justin Whear wrote:Doesn't need to be PHP, just show one example statically and switch it with a random one with JS.A process for rounding numbers.Thanks Justin. Could someone take this? We don't have PHP code for rotating examples randomly yet. -- Andrei
May 02 2015
On Sunday, 3 May 2015 at 02:48:32 UTC, Vladimir Panteleev wrote:Doesn't need to be PHPcould also be D
May 02 2015
On 5/2/15 7:51 PM, Adam D. Ruppe wrote:On Sunday, 3 May 2015 at 02:48:32 UTC, Vladimir Panteleev wrote:"code or it didn't happen" -- AndreiDoesn't need to be PHPcould also be D
May 02 2015
On 5/2/15 7:48 PM, Vladimir Panteleev wrote:On Saturday, 2 May 2015 at 22:23:01 UTC, Andrei Alexandrescu wrote:That'd work. I gather you just volunteered :o). -- AndreiOn Friday, 1 May 2015 at 17:17:09 UTC, Justin Whear wrote:Doesn't need to be PHP, just show one example statically and switch it with a random one with JS.A process for rounding numbers.Thanks Justin. Could someone take this? We don't have PHP code for rotating examples randomly yet. -- Andrei
May 02 2015
On Sunday, 3 May 2015 at 04:14:40 UTC, Andrei Alexandrescu wrote:On 5/2/15 7:48 PM, Vladimir Panteleev wrote:https://github.com/D-Programming-Language/dlang.org/pull/988On Saturday, 2 May 2015 at 22:23:01 UTC, Andrei Alexandrescu wrote:That'd work. I gather you just volunteered :o). -- AndreiOn Friday, 1 May 2015 at 17:17:09 UTC, Justin Whear wrote:Doesn't need to be PHP, just show one example statically and switch it with a random one with JS.A process for rounding numbers.Thanks Justin. Could someone take this? We don't have PHP code for rotating examples randomly yet. -- Andrei
May 04 2015
Arrrg, formatting got torn up. Here's a Dpaste: http://dpaste.dzfl.pl/ca190950f199
May 04 2015