D do not know which function to use apparently
Steven Schveighoffer
schveiguy at gmail.com
Tue Dec 11 14:53:02 UTC 2018
On 12/11/18 9:47 AM, Narxa wrote:
> On Tuesday, 11 December 2018 at 14:22:30 UTC, Adam D. Ruppe wrote:
>> On Tuesday, 11 December 2018 at 14:16:05 UTC, Narxa wrote:
>>> int var = floor(sqrt(n)) // where 'n' is a 'const int'
>>
>> You can just cast it to float:
>>
>> floor(sqrt( cast(float) n ));
>>
>> and it will work.
>
> It produced the following error:
> --------------------------------
> Error: cannot implicitly convert expression floor(sqrt(cast(float)n)) of
> type float to int
>
>
> I am using 'dmd' compiler if it matters.
You need to cast the result back to int.
-Steve
More information about the Digitalmars-d-learn
mailing list