首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

#double

我这个代码怎样修改才可以在Pine Script 上运行?

请各位大佬帮我看看这道题求sinx?

为什么java.lang.Integer和java.lang.Double的最小上界被推断为非循环类型?

不是一个答案,而是隐含在REPL中的一些线索。编译器不认为类型相同。推断的类型更具体: // some type aliases to make reading easier type Dx = java.lang.Double type Ix = java.lang.Integer // the type the compiler came up with: type Inferred = Number with Comparable[ _ >: Dx with Ix <: Number with Comparable[_ >: Dx with Ix <: Number]] // your type: type Soc = Number with Comparable[_ >: Dx with Ix <: Number] 检查我做了正确的类型别名: val d = new java.lang.Double(4) val i = new java.lang.Integer(4) val foo: Soc = if (true) d else i // foo: Soc = 4.0 val foo: Inferred = if (true) d else i // foo: Inferred = 4.0 类型不一样: implicitly[Soc =:= Inferred] // error 你的类型是推断类型的超类型: implicitly[Inferred <:< Soc] // ok implicitly[Soc <:< Inferred] // error 所以根据编译器,它提出了一个更具体的类型 - 这是正确的做法。请注意,用例可以像这样重新创建: class N // like java.lang.Number trait C[T] // like Comparable class I extends N with C[I] // like java.lang.Integer class D extends N with C[D] // like java.lang.Double type DI = N with C[_ >: D with I <: N with C[_ >: D with I <: N]] // DI is like the type inferred type DI_SOC = N with C[_ >: D with I <: N] // your type val foo: DI = if (true) new D else new I // ok val foo: DI_SOC = if (true) new D else new I // ok implicitly[DI =:= DI_SOC] // error implicitly[DI <:< DI_SOC] // DI_SOC super type of DI implicitly[DI_SOC <:< DI] // error 所以我想知道我们是否可以创建一个类DI_SOC但不是一个类DI,这会说明DI和DI_SOC不是相同的类型,而且类型不是最小上界。 好吧,在离开计算机一段时间后再试一次。这是一个类,DI_SOC但不是DI: class A extends N with C[N] implicitly[A <:< DI_SOC] // ok implicitly[A <:< DI] // error 应用于原始用例: class Ax extends Number with Comparable[Number] { def doubleValue() = 0d def floatValue() = 0f def intValue() = 0 def longValue() = 0L def compareTo(n: Number) = 0 } implicitly[Ax <:< Soc] // ok implicitly[Ax <:< Inferred] // error 因此,类型Soc和Inferred是不相同的,Ax证明Number with Comparable[_ >: Double with Integer <: Number]是不是最少的上限... 换句话说,两者之间有一些空间,Double with Integer <: ? <: Number但没有太大的空间Double with Integer <: ? <: Number with Comparable[_ >: Double with Integer <: Number]... 展开详请
不是一个答案,而是隐含在REPL中的一些线索。编译器不认为类型相同。推断的类型更具体: // some type aliases to make reading easier type Dx = java.lang.Double type Ix = java.lang.Integer // the type the compiler came up with: type Inferred = Number with Comparable[ _ >: Dx with Ix <: Number with Comparable[_ >: Dx with Ix <: Number]] // your type: type Soc = Number with Comparable[_ >: Dx with Ix <: Number] 检查我做了正确的类型别名: val d = new java.lang.Double(4) val i = new java.lang.Integer(4) val foo: Soc = if (true) d else i // foo: Soc = 4.0 val foo: Inferred = if (true) d else i // foo: Inferred = 4.0 类型不一样: implicitly[Soc =:= Inferred] // error 你的类型是推断类型的超类型: implicitly[Inferred <:< Soc] // ok implicitly[Soc <:< Inferred] // error 所以根据编译器,它提出了一个更具体的类型 - 这是正确的做法。请注意,用例可以像这样重新创建: class N // like java.lang.Number trait C[T] // like Comparable class I extends N with C[I] // like java.lang.Integer class D extends N with C[D] // like java.lang.Double type DI = N with C[_ >: D with I <: N with C[_ >: D with I <: N]] // DI is like the type inferred type DI_SOC = N with C[_ >: D with I <: N] // your type val foo: DI = if (true) new D else new I // ok val foo: DI_SOC = if (true) new D else new I // ok implicitly[DI =:= DI_SOC] // error implicitly[DI <:< DI_SOC] // DI_SOC super type of DI implicitly[DI_SOC <:< DI] // error 所以我想知道我们是否可以创建一个类DI_SOC但不是一个类DI,这会说明DI和DI_SOC不是相同的类型,而且类型不是最小上界。 好吧,在离开计算机一段时间后再试一次。这是一个类,DI_SOC但不是DI: class A extends N with C[N] implicitly[A <:< DI_SOC] // ok implicitly[A <:< DI] // error 应用于原始用例: class Ax extends Number with Comparable[Number] { def doubleValue() = 0d def floatValue() = 0f def intValue() = 0 def longValue() = 0L def compareTo(n: Number) = 0 } implicitly[Ax <:< Soc] // ok implicitly[Ax <:< Inferred] // error 因此,类型Soc和Inferred是不相同的,Ax证明Number with Comparable[_ >: Double with Integer <: Number]是不是最少的上限... 换句话说,两者之间有一些空间,Double with Integer <: ? <: Number但没有太大的空间Double with Integer <: ? <: Number with Comparable[_ >: Double with Integer <: Number]
领券