From 367565a3ee6e2c38add442a4f5ccbb28757e4e5b Mon Sep 17 00:00:00 2001 From: Brandon High Date: Thu, 5 Mar 2020 16:11:42 -0800 Subject: [PATCH] Switch from casting to_f to using fdiv dividing floats This commit updates places where previously we were casting both terms in a float division into floats in order to ensure that float division occurs to use the `fdiv` method, which will always do float division and is available on both `Floats` and `Integers` because they are both `Numeric`. --- lib/vmpooler/api/helpers.rb | 2 +- lib/vmpooler/providers/vsphere.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/vmpooler/api/helpers.rb b/lib/vmpooler/api/helpers.rb index 6d0cbe6..0b98143 100644 --- a/lib/vmpooler/api/helpers.rb +++ b/lib/vmpooler/api/helpers.rb @@ -216,7 +216,7 @@ module Vmpooler capacity[:current] = get_total_across_pools_redis_scard(pools, 'vmpooler__ready__', backend) if capacity[:total] > 0 - capacity[:percent] = ((capacity[:current].to_f / capacity[:total].to_f) * 100.0).round(1) + capacity[:percent] = (capacity[:current].fdiv(capacity[:total]) * 100.0).round(1) end capacity diff --git a/lib/vmpooler/providers/vsphere.rb b/lib/vmpooler/providers/vsphere.rb index 256e55a..8526dea 100644 --- a/lib/vmpooler/providers/vsphere.rb +++ b/lib/vmpooler/providers/vsphere.rb @@ -759,7 +759,7 @@ module Vmpooler return nil if cpu_usage.nil? cpu_size = host.summary.hardware.cpuMhz * host.summary.hardware.numCpuCores - (cpu_usage.to_f / cpu_size.to_f) * 100 + cpu_usage.fdiv(cpu_size) * 100 end def memory_utilization_for(host) @@ -767,7 +767,7 @@ module Vmpooler return nil if memory_usage.nil? memory_size = host.summary.hardware.memorySize / 1024 / 1024 - (memory_usage.to_f / memory_size.to_f) * 100 + memory_usage.fdiv(memory_size) * 100 end def get_average_cluster_utilization(hosts)