Re: Idiomatic D code to avoid or detect devision by zero

2020-08-06 Thread Martin Tschierschke via Digitalmars-d-learn
On Monday, 3 August 2020 at 15:33:54 UTC, Dominikus Dittes Scherkl wrote: [...] For really long expressions you could also split it on multiple lines: c = (b_expression == 0) ? (d_longer_expression) : (a_expression/b_expression); +1 looks clean!

Re: Idiomatic D code to avoid or detect devision by zero

2020-08-03 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Monday, 3 August 2020 at 14:50:36 UTC, Steven Schveighoffer wrote: On 8/3/20 5:53 AM, Martin Tschierschke wrote: I prefer putting additional bracket around For really long expressions you could also split it on multiple lines: c = (b_expression == 0) ? (d_longer_expression) :

Re: Idiomatic D code to avoid or detect devision by zero

2020-08-03 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/3/20 5:53 AM, Martin Tschierschke wrote: On Friday, 31 July 2020 at 14:18:15 UTC, Steven Schveighoffer wrote: On 7/31/20 9:55 AM, Martin Tschierschke wrote: What would be the idiomatic way to write a floating point division occuring inside a loop and handle the case of division by zero.

Re: Idiomatic D code to avoid or detect devision by zero

2020-08-03 Thread Martin Tschierschke via Digitalmars-d-learn
On Friday, 31 July 2020 at 14:18:15 UTC, Steven Schveighoffer wrote: On 7/31/20 9:55 AM, Martin Tschierschke wrote: What would be the idiomatic way to write a floating point division occuring inside a loop and handle the case of division by zero. c = a/b; // b might be zero sometimes, than

Re: Idiomatic D code to avoid or detect devision by zero

2020-08-03 Thread Martin Tschierschke via Digitalmars-d-learn
On Friday, 31 July 2020 at 15:19:25 UTC, Andrea Fontana wrote: On Friday, 31 July 2020 at 13:55:18 UTC, Martin Tschierschke wrote: What would be the idiomatic way to write a floating point division occuring inside a loop and handle the case of division by zero. c = a/b; // b might be zero

Re: Idiomatic D code to avoid or detect devision by zero

2020-07-31 Thread Andrea Fontana via Digitalmars-d-learn
On Friday, 31 July 2020 at 13:55:18 UTC, Martin Tschierschke wrote: What would be the idiomatic way to write a floating point division occuring inside a loop and handle the case of division by zero. c = a/b; // b might be zero sometimes, than set c to an other value (d). (In the moment I

Re: Idiomatic D code to avoid or detect devision by zero

2020-07-31 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/31/20 9:55 AM, Martin Tschierschke wrote: What would be the idiomatic way to write a floating point division occuring inside a loop and handle the case of division by zero. c = a/b; // b might be zero sometimes, than set c to an other value (d). (In the moment I check the divisor being