View Full Version : Divide by rational number
Terka
28th March 2013, 14:11
f=1.73
b=a.LanczosResize(width(a)/f,height(a)/f)
does not work.
what is wrong?
Groucho2004
28th March 2013, 14:54
This should work:
mod = 2
f = 1.73
b = a.LanczosResize(round((float(width(a))/f) / float(mod)) * mod, round((float(height(a))/f) / float(mod)) * mod)
Thread with a similar subject here (http://forum.doom9.org/showthread.php?t=167431).
wonkey_monkey
28th March 2013, 17:27
I always go for:
width(a)*1.0/f
instead of
float(width(a))/f
As I find it a little less brackety.
Wouldn't C, in the case of int/float, return an int? Whereas Avisynth seems to be returning a floored but invalid (for resize) type?
Gavino
28th March 2013, 18:00
Wouldn't C, in the case of int/float, return an int? Whereas Avisynth seems to be returning a floored but invalid (for resize) type?
int/float gives a float in both C and Avisynth.
This gives an error since the resizers expect ints for width and height.
wonkey_monkey
29th March 2013, 00:03
But a floored float, is that right? Otherwise why not just do round(width(a)/f)?
Gavino
29th March 2013, 00:40
But a floored float, is that right? Otherwise why not just do round(width(a)/f)?
No, the float result is fully accurate, and you can just do round(width(a)/f) (as long as f is known to be a float).
Groucho2004's solution:
b = a.LanczosResize(round((float(width(a))/f) / float(mod)) * mod, round((float(height(a))/f) / float(mod)) * mod)
could be written simply as
b = a.LanczosResize(round((width(a)/f) / mod) * mod, round((height(a)/f) / mod) * mod)
wonkey_monkey
29th March 2013, 19:15
Ah! My mistake. I was dividing by an int.
ajp_anton
29th March 2013, 20:12
Why not introduce "./" or something similar as a divide that always returns a float?
Terka
2nd April 2013, 11:27
Thanks guys for help!
vBulletin® v3.8.11, Copyright ©2000-2025, vBulletin Solutions Inc.