Re: float price; if (price == float.nan) { // initialized } else { // uninitialized } ... valid ?

2021-07-08 Thread bauss via Digitalmars-d-learn
On Wednesday, 30 June 2021 at 16:41:40 UTC, someone wrote: On Wednesday, 30 June 2021 at 16:24:38 UTC, Andre Pany wrote: Side note: in case you want to work with money, you may consider using a specific data type like https://code.dlang.org/packages/money instead of float/double. Yes, I've s

Re: float price; if (price == float.nan) { // initialized } else { // uninitialized } ... valid ?

2021-07-08 Thread bauss via Digitalmars-d-learn
On Wednesday, 30 June 2021 at 16:19:35 UTC, someone wrote: On Wednesday, 30 June 2021 at 10:38:05 UTC, jmh530 wrote: You've never given something away for free? ... more often than usual LoL Now, seriously, something for free has not a price = 0, it has NO price, that's what null is for; we

Re: float price; if (price == float.nan) { // initialized } else { // uninitialized } ... valid ?

2021-06-30 Thread someone via Digitalmars-d-learn
On Wednesday, 30 June 2021 at 16:24:38 UTC, Andre Pany wrote: Side note: in case you want to work with money, you may consider using a specific data type like https://code.dlang.org/packages/money instead of float/double. Yes, I've seen it, and in a previous-unrelated post I commented I am p

Re: float price; if (price == float.nan) { // initialized } else { // uninitialized } ... valid ?

2021-06-30 Thread Andre Pany via Digitalmars-d-learn
On Wednesday, 30 June 2021 at 03:15:46 UTC, someone wrote: Is the following code block valid ? ```d float price; /// initialized as float.nan by default ... right ? if (price == float.nan) { /// writeln("initialized"); } else { /// writeln("uninitialized"); } ``` if so, the following

Re: float price; if (price == float.nan) { // initialized } else { // uninitialized } ... valid ?

2021-06-30 Thread someone via Digitalmars-d-learn
On Wednesday, 30 June 2021 at 10:38:05 UTC, jmh530 wrote: You've never given something away for free? ... more often than usual LoL Now, seriously, something for free has not a price = 0, it has NO price, that's what null is for; we use zero for the lack of null.

Re: float price; if (price == float.nan) { // initialized } else { // uninitialized } ... valid ?

2021-06-30 Thread someone via Digitalmars-d-learn
On Wednesday, 30 June 2021 at 09:36:34 UTC, Dennis wrote: A `string` is not a class but an array, an `immutable(char)[]`. You're right. My fault.

Re: float price; if (price == float.nan) { // initialized } else { // uninitialized } ... valid ?

2021-06-30 Thread jmh530 via Digitalmars-d-learn
On Wednesday, 30 June 2021 at 04:17:19 UTC, someone wrote: On Wednesday, 30 June 2021 at 03:55:05 UTC, Vladimir Panteleev wrote: If you want to give any type a "null" value, you could use [`std.typecons.Nullable`](https://dlang.org/library/std/typecons/nullable.html). At LEAST for some thing

Re: float price; if (price == float.nan) { // initialized } else { // uninitialized } ... valid ?

2021-06-30 Thread Dennis via Digitalmars-d-learn
On Wednesday, 30 June 2021 at 03:52:51 UTC, someone wrote: at least I can do nulls with strings since it a class :) A `string` is not a class but an array, an `immutable(char)[]`. For arrays, `null` is equal to an empty array `[]`. ```D void main() { string s0 = null; string s1 = [];

Re: float price; if (price == float.nan) { // initialized } else { // uninitialized } ... valid ?

2021-06-29 Thread someone via Digitalmars-d-learn
On Wednesday, 30 June 2021 at 03:55:05 UTC, Vladimir Panteleev wrote: If you want to give any type a "null" value, you could use [`std.typecons.Nullable`](https://dlang.org/library/std/typecons/nullable.html). At LEAST for some things with currency types like prices which cannot be zero beca

Re: float price; if (price == float.nan) { // initialized } else { // uninitialized } ... valid ?

2021-06-29 Thread Mathias LANG via Digitalmars-d-learn
On Wednesday, 30 June 2021 at 04:03:24 UTC, someone wrote: On Wednesday, 30 June 2021 at 03:51:47 UTC, Mathias LANG wrote: ... is far from pretty but it works as expected, thanks for your tip ! Can be made a bit prettier with UFCS: ```d import std.math : isNaN; float lnumStockPricePrecedin

Re: float price; if (price == float.nan) { // initialized } else { // uninitialized } ... valid ?

2021-06-29 Thread someone via Digitalmars-d-learn
On Wednesday, 30 June 2021 at 03:55:05 UTC, Vladimir Panteleev wrote: If you want to give any type a "null" value, you could use [`std.typecons.Nullable`](https://dlang.org/library/std/typecons/nullable.html). Practically Nullable!T stores a T and a bool. I like the idea :)

Re: float price; if (price == float.nan) { // initialized } else { // uninitialized } ... valid ?

2021-06-29 Thread someone via Digitalmars-d-learn
On Wednesday, 30 June 2021 at 03:51:47 UTC, Mathias LANG wrote: or use `std.math.isNaN`. ```d import std.math : isNaN; float lnumStockPricePreceding; foreach (float lnumStockPrice; ludtStockPriceEvolution.range) if (! isNan(lnumStockPricePreceding)) { /// do something } ln

Re: float price; if (price == float.nan) { // initialized } else { // uninitialized } ... valid ?

2021-06-29 Thread Vladimir Panteleev via Digitalmars-d-learn
On Wednesday, 30 June 2021 at 03:52:51 UTC, someone wrote: One of the things I do not like with D, and it causes me to shoot me on the foot over and over, is the lack of null for *every* data type. Things like: If you want to give any type a "null" value, you could use [`std.typecons.Nullable

Re: float price; if (price == float.nan) { // initialized } else { // uninitialized } ... valid ?

2021-06-29 Thread someone via Digitalmars-d-learn
On Wednesday, 30 June 2021 at 03:32:27 UTC, Vladimir Panteleev wrote: Comparison with `nan` always results in `false`: THAT explains a lot ! See section 10.11.5: missed it. One of the things I do not like with D, and it causes me to shoot me on the foot over and over, is the lack of nul

Re: float price; if (price == float.nan) { // initialized } else { // uninitialized } ... valid ?

2021-06-29 Thread Mathias LANG via Digitalmars-d-learn
On Wednesday, 30 June 2021 at 03:32:27 UTC, Vladimir Panteleev wrote: On Wednesday, 30 June 2021 at 03:15:46 UTC, someone wrote: Is the following code block valid ? Comparison with `nan` always results in `false`: See section 10.11.5: https://dlang.org/spec/expression.html#equality_expressio

Re: float price; if (price == float.nan) { // initialized } else { // uninitialized } ... valid ?

2021-06-29 Thread Vladimir Panteleev via Digitalmars-d-learn
On Wednesday, 30 June 2021 at 03:15:46 UTC, someone wrote: Is the following code block valid ? Comparison with `nan` always results in `false`: See section 10.11.5: https://dlang.org/spec/expression.html#equality_expressions You can use the `is` operator to perform bitwise comparison, or us

float price; if (price == float.nan) { // initialized } else { // uninitialized } ... valid ?

2021-06-29 Thread someone via Digitalmars-d-learn
Is the following code block valid ? ```d float price; /// initialized as float.nan by default ... right ? if (price == float.nan) { /// writeln("initialized"); } else { /// writeln("uninitialized"); } ``` if so, the following one should be valid too ... right ? ```d float price; if