lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


2010/5/13 Luiz Henrique de Figueiredo <lhf@tecgraf.puc-rio.br>:
>> > require"bc"
>> > a = bc.number('1')
>> > =a/0
>> nil
>>
>> Why nil?
>> If lbc has redefined divide operator, it must returned inf too?
>
> bc functions return bc numbers but bc does not support inf or nan.
> So lbc returns nil on error, which is consisten with other Lua libraries.
>
> If you want to change this behavior, it's a simple one-line change:
>
>  static int Bdiv(lua_State *L)                 /** div(x,y) */
>  {
>   bc_num a=Bget(L,1);
>   bc_num b=Bget(L,2);
>   bc_num c=NULL;
> /* if (bc_divide(a,b,&c,DIGITS)!=0) return 0; */
>   if (bc_divide(a,b,&c,DIGITS)!=0) lua_pushnumber(L,1/0); else
>   Bnew(L,c);
>   return 1;
>  }
>



-- 
Regards,
Yuri Kozlov