gsl-shell.git - gsl-shell

index : gsl-shell.git
gsl-shell
summary refs log tree commit diff
path: root/matrix.lua
diff options
context:
space:
mode:
authorFrancesco Abbate <francesco.bbt@gmail.com>2013年02月04日 21:46:49 +0100
committerFrancesco Abbate <francesco.bbt@gmail.com>2013年02月04日 21:46:49 +0100
commit858c66cac8902ad7fd32d10ae82bb885f9774904 (patch)
treed9d5e118f3cc21336da56263470a6ffd3462f47d /matrix.lua
parentfe5cea0c67ac178d6476beb64f2bd5fcf4acb0f0 (diff)
parent9b63ca608ee573a2588ad14a3a46a5ca9f00f9a2 (diff)
downloadgsl-shell-858c66cac8902ad7fd32d10ae82bb885f9774904.tar.gz
Merge branch 'factor-labels' into gdt-new
Diffstat (limited to 'matrix.lua')
-rw-r--r--matrix.lua 23
1 files changed, 18 insertions, 5 deletions
diff --git a/matrix.lua b/matrix.lua
index 87df4581..d7c5e75b 100644
--- a/matrix.lua
+++ b/matrix.lua
@@ -3,7 +3,7 @@
local ffi = require 'ffi'
local gsl = require 'gsl'
-local sqrt, abs = math.sqrt, math.abs
+local sqrt, abs, floor = math.sqrt, math.abs, math.floor
local format = string.format
local check = require 'check'
@@ -208,21 +208,34 @@ local function itostr(im, eps, fmt, signed)
end
end
+local function is_small_integer(x)
+ local ax = abs(x)
+ return (ax < 2^31 and floor(ax) == ax)
+end
+
local function recttostr(x, y, eps)
local x_sub, y_sub = abs(x) < eps, abs(y) < eps
- local fmt = '%.8g'
+ local fmt_x, fmt_y = '%.8g', '%.8g'
+ if is_small_integer(x) then
+ fmt_x = '%.0f'
+ x_sub = false
+ end
+ if is_small_integer(y) then
+ fmt_y = '%.0f'
+ y_sub = false
+ end
if not x_sub then
local sign = x+eps < 0 and '-' or ''
local ax = abs(x)
if y_sub then
- return format('%s'..fmt, sign, ax)
+ return format('%s'..fmt_x, sign, ax)
else
- return format('%s'..fmt..'%s', sign, ax, itostr(y, eps, fmt, true))
+ return format('%s'..fmt_x..'%s', sign, ax, itostr(y, eps, fmt_y, true))
end
else
- return (y_sub and '0' or itostr(y, eps, fmt, false))
+ return (y_sub and '0' or itostr(y, eps, fmt_y, false))
end
end
generated by cgit v1.2.3 (git 2.25.1) at 2025年09月11日 21:09:08 +0000

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