On 1/19/21 9:28 PM, Per Nordlöw wrote:
On Tuesday, 19 January 2021 at 16:14:17 UTC, drug wrote:
https://dlang.org/phobos/std_bitmanip.html#FloatRep
Doesn't this pattern already cover all possible cases of `value` needed?
void f(double value)
{
auto lvalue = cast(long)value;
if
On Tuesday, 19 January 2021 at 21:04:51 UTC, kdevel wrote:
And then? I mean: What do you want to do with the long what
could not
be done with the double in the first place?
Motivated question.
We want to propagate to our system locally that a double received
from a network communication
On Tuesday, 19 January 2021 at 11:42:17 UTC, Per Nordlöw wrote:
I want to convert a double to a long if conversion is lossless
(without fractional part, non-nan, non-inf, within long-range,
etc).
And then? I mean: What do you want to do with the long what could
not
be done with the double
On 1/19/21 10:28 AM, Per Nordlöw wrote:
> On Tuesday, 19 January 2021 at 16:14:17 UTC, drug wrote:
>>>https://dlang.org/phobos/std_bitmanip.html#FloatRep
>
> Doesn't this pattern already cover all possible cases of `value` needed?
I think so. I just remembered FloatRep as a cleaner tool
On Tuesday, 19 January 2021 at 16:14:17 UTC, drug wrote:
https://dlang.org/phobos/std_bitmanip.html#FloatRep
Doesn't this pattern already cover all possible cases of `value`
needed?
void f(double value)
{
auto lvalue = cast(long)value;
if (lvalue == value) // `value` lacks
On Tuesday, 19 January 2021 at 17:03:53 UTC, Ali Çehreli wrote:
I think it would be a useful improvement.
Indeed. Maybe Ilya could help out adding this to dmd.
I'm probably missing something, but on the off chance you aren't
aware, there is http://phobos.dpldocs.info/std.math.modf.html .
On 1/19/21 8:14 AM, drug wrote:
> P.S. shouldn't compiler emit the error if a literal can't be represented
> lossless?
I think it would be a useful improvement.
Ali
On 1/19/21 6:50 PM, Ali Çehreli wrote:
On 1/19/21 6:04 AM, drug wrote:
> Another (low level) way is to shift mantissa left by exponent value.
Luckily, we already have a helper in Phobos:
https://dlang.org/phobos/std_bitmanip.html#FloatRep
Ali
That makes life simpler, thanks for
On 1/19/21 6:04 AM, drug wrote:
> Another (low level) way is to shift mantissa left by exponent value.
Luckily, we already have a helper in Phobos:
https://dlang.org/phobos/std_bitmanip.html#FloatRep
Ali
On 1/19/21 5:04 PM, drug wrote:
On 1/19/21 4:48 PM, Per Nordlöw wrote:
On Tuesday, 19 January 2021 at 13:36:58 UTC, Steven Schveighoffer wrote:
Use a cast instead.
const lvalue = cast(long)value;
Ahh, good point.
Followd by a compare of the original value I presume.
don't forget to check
On 1/19/21 4:48 PM, Per Nordlöw wrote:
On Tuesday, 19 January 2021 at 13:36:58 UTC, Steven Schveighoffer wrote:
Use a cast instead.
const lvalue = cast(long)value;
Ahh, good point.
Followd by a compare of the original value I presume.
don't forget to check by std.math.isFinite before
On Tuesday, 19 January 2021 at 13:36:58 UTC, Steven Schveighoffer
wrote:
Use a cast instead.
const lvalue = cast(long)value;
Ahh, good point.
Followd by a compare of the original value I presume.
On 1/19/21 6:42 AM, Per Nordlöw wrote:
I want to convert a double to a long if conversion is lossless (without
fractional part, non-nan, non-inf, within long-range, etc).
I currently have
void foo()
{
const double value = 10.1;
try
{
import std.conv : to;
I want to convert a double to a long if conversion is lossless
(without fractional part, non-nan, non-inf, within long-range,
etc).
I currently have
void foo()
{
const double value = 10.1;
try
{
import std.conv : to;
const lvalue = value.to!long;
if (lvalue
15 matches
Mail list logo