lua-users home
lua-l archive

Use of math.huge on 64bit Linux

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


 Okay, I'm using Lua 5.1.5 (and all the patches [1]) and for the life of
me, I can't figure out what I'm doing wrong. I have this script:
	proc = require "org.conman.process" -- [2]
	print(math.huge)
	proc.limits.soft.core = math.huge
	print(proc.limits.soft.core)
 On 32-bit Linux, the output is as expected:
	inf
	inf
 But on two different 64-bit Linux systems, I get:
	inf
	0
 I'm not seeing any obvious issues with the function [3]. I traced into
the function, and after it executes:
	ival = lua_tonumber(L,3);
ival is 0, when it should be HUGE_VAL (which on Linux, prints out as 'inf'). 
Tracing into lua_tonumber() doesn't reveal anything, so next, write a
simplified test program to hopefully isolate the issue:
#include <stdio.h>
#include <lua.h>
#include <lauxlib.h>
static int huge(lua_State *L)
{
 lua_Number ival;
 
 if (lua_isnumber(L,1))
 ival = lua_tonumber(L,1);
 else
 return 0;
 
 printf("%f\n",ival);
 return 0;
}
int luaopen_huge(lua_State *L)
{
 lua_pushcfunction(L,huge);
 return 1;
}
And the following script:
	huge = require "huge"
	huge(math.huge)
	huge(0)
Running this on both 64-bit systems, the output is:
	inf
	0
which is *NOT* what I expected (and is, in fact, correct). So obviously, I
haven't isolated the issue, but I'm not just seeing what could be going
wrong. I don't think it's because of the fact that I compiled everything
into a custom Lua interpreter with all the modules built in, because I built
in the above module and it still worked.
 I'm missing something obvious and I'm not seeing it.
 -spc (Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaah!)
[1]	http://www.lua.org/bugs.html#5.1.5
[2]	https://github.com/spc476/lua-conmanorg/blob/master/src/process.c
[3]	https://github.com/spc476/lua-conmanorg/blob/master/src/process.c#L1184

AltStyle によって変換されたページ (->オリジナル) /