# Practice with elemental function

**URL:** <https://fortran-lang.discourse.group/t/practice-with-elemental-function/10659>\
**Category:** Uncategorized\
**Created:** [January 24, 2026, 10:30pm UTC](https://fortran-lang.discourse.group/t/practice-with-elemental-function/10659 "2026-01-24T22:30:53Z")\
**Posts on this page:** 1\
**Showing post:** 28

<div class="post-metadata">

**Author:** ![CRquantum](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/crquantum/32/730_2.png) [@CRquantum](https://fortran-lang.discourse.group/u/CRquantum)\
**Post date:** [January 30, 2026, 3:48am UTC](https://fortran-lang.discourse.group/t/practice-with-elemental-function/10659/28 "2026-01-30T03:48:26Z")

</div>

> [@Beliavsky](#):
>
> So cannot safely write `a = merge(sqrt(b), 0.0, b >= 0)` with `b` real, but you can write `a = (b >= 0 ? sqrt(b) : 0.0)`.

Could you please elaborate a little bit more, about why “cannot safely write `a = merge(sqrt(b), 0.0, b >= 0)` with `b` real”?  
and why it is safe to write `a = (b >= 0 ? sqrt(b) : 0.0)`?  
Thanks!

PS.  
I know a topic about merge() is below for example,

> [@Is there another function in Fortran like \`merge\` that does not evaluate its arguments?](https://fortran-lang.discourse.group/t/is-there-another-function-in-fortran-like-merge-that-does-not-evaluate-its-arguments/7414):
>
> The merge function does not evaluate its arguments, unless they are needed. Here is a simple test program, that passes: program test\_merge implicit none integer :: i, j i = merge(f1(), f2(), .true.) if (j /= 1) error stop if (i /= 10) error stop i = merge(f1(), f2(), .false.) if (j /= 2) error stop if (i /= 20) error stop contains integer function f1() result(r) j = 1 r = 10 end function integer function f2() result(r) j = 2 r = 20 end function end program A…

---

_[View the full topic](https://fortran-lang.discourse.group/t/practice-with-elemental-function/10659)._
