On Fri, 20 Jun 2008 17:31:03 +0200, Bram Moolenaar wrote:

> I think it's:
>       if (f > 0)
>         return floor(f + 0.5)
>       else
>         return ceil(f - 0.5)
> 
> Otherwise -1.5 doesn't work like round() does.  Glad we have a test to
> verify this :-)

Yes, I had test my round() function with another Vim function in
eval.txt

I have now in eval.c:

============ trunc ===========
    if (get_float_arg(argvars, &f) == OK)
#if !defined(__BORLANDC__)
        rettv->vval.v_float = trunc(f);
#else
        if (f < 0)
            rettv->vval.v_float = ceil(f);
        else
            rettv->vval.v_float = floor(f);
#endif
    else
        rettv->vval.v_float = 0.0;
============ round ============
    if (get_float_arg(argvars, &f) == OK)
#if !defined(__BORLANDC__)
        rettv->vval.v_float = round(f);
#else
        if (f > 0)
            rettv->vval.v_float = floor(f + 0.5);
        else
            rettv->vval.v_float = ceil(f - 0.5);
#endif
    else
        rettv->vval.v_float = 0.0;
=================================

> In the FreeBSD manual pages ceil() and floor() are mentioned to be
> according to C90 and C99, while round() and trunc() are only in C99.
> 
> How about strtod(), it's only in C99 as well.

String Vim function str2float with a strtod() call works fine.
-- 
Patrick Texier, 
Frulon, 36190 Orsennes, France (46°31'N, 01°41'E)
<http://www.genindre.org>
<http://www.gpsql.org> <http://www.footsql.org>

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Raspunde prin e-mail lui