我正在寻找OCaml中的用法示例来演示简单的属性或定理.给定二叉树的ocaml定义的示例可以证明节点的最大数量是2 ^(h + 1)-1.
我已经为二进制树和图形找到了这样的例子,但没有别的......任何建议或链接?
我需要通过串行线(RS-232)接收来自Arduino的十六进制编码单精度大端浮点值.如何将它们转换为具有双精度的大端的Python浮点数?
Arduino发送类似"8192323E"的东西,在Python中我希望有0.174387.我发现" 将十六进制转换为浮动 "但似乎所有这些都不适用于单精度浮点数.
从链接页面看,这很有希望:
from ctypes import *
def convert(s):
i = int(s, 16) # convert from hex to a Python int
cp = pointer(c_int(i)) # make this into a c integer
fp = cast(cp, POINTER(c_float)) # cast the int pointer to a float pointer
return fp.contents.value # dereference the pointer, get the float
Run Code Online (Sandbox Code Playgroud)
但它仍然不适用于我的单精度浮子.
在Java(Processing)中,我已经能够做到这一点:
float decodeFloat(String inString) {
byte [] inData = new byte[4];
inString = inString.substring(2, 10); // discard the leading "f:"
inData[0] = …
Run Code Online (Sandbox Code Playgroud) 我正在尝试实现扩展类P的类C的__ mul __方法.类P具有__ mul __的实现,但这仅适用于该类型的元素(P()*P()).
所以在C __ mul __中我希望在参数为float时为float实现简单乘法.当它不是我想要使用P的__ mul __ ..但这导致问题,如在P的__ mul __那是"返回P(某事)"..
因此,基本上它们最初是C型的事实在一些操作之后就会丢失.
以下代码更好地解释了该问题.
任何想法解决这个?
class MyFloat(object): def __init__(self, a): self.a = a def __mul__(self, other): return MyFloat(self.a * other.a) def __repr__(self): return str(self.a) class MyFloatExt(MyFloat): def __init__(self, a): MyFloat.__init__(self, a) def __add__(self, other): return MyFloatExt(self.a + other.a) def __mul__(self, other): if type(other) == (int, long, float): return MyFloatExt(self.a * other) else: return MyFloat.__mul__(self, other) a = MyFloatExt(0.5) b = MyFloatExt(1.5) c = a + b print c …
我在我正在开发的网站上设置了Ad Gallery(基于Jquery的图库插件,请参阅http://coffeescripter.com/code/ad-gallery/).在最近的浏览器中一切正常工作..唯一的问题是IE7抛出JS错误并停止执行脚本.
我没有访问IE7的调试工具,所以我无法真正调查问题.