公制和英制内部代表 [英] Metric and Imperial internal representation

查看:46
本文介绍了公制和英制内部代表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在应用程序中使用公制和英制距离单位.一种方法是在设备上标记数字.我不想走这条路.

I want to use metric and Imperial distance units in an application. One way of doing this is tagging a number with the unit. I don't want to go this route.

我想使用一种内部表示形式,可以将英制精确地保持在1/64英寸(0.2毫米)以下.我想出了8128 RSU(确实很小的单位),它可以被64和254整除,这正是我想要的.

I want to use one internal representation that can exactly hold imperial down to 1/64 of an inch and 0.2mm. I have come up with 8128 RSU (really small units) that is divisible by 64 and 254, which does what I want.

这接近2 ^ 13,这让我想知道是否有更优化的方法?

This is close to 2^13, and it has got me wondering if there is a more optimal way of doing this?

有什么想法吗?

推荐答案

一个稍微简单的解决方案是使用其他小型单位",以使1 OSU = 1/320 mm.按照这种约定,1/64将是127 OSU,0.2mm将是64 OSU.由于127和64是相对质数,这是您可以获得的最低分母.

A slightly simpler solution might be to use "Other small units" so that 1 OSU = 1/320 mm. With this convention, 1/64" would be 127 OSU and 0.2mm would be 64 OSU. Since 127 and 64 are relative primes, this is the lowest denominator you can get.

这篇关于公制和英制内部代表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆