Japan posts gain in machinery orders