Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compile time float64 are silently converted to float32 #15203

Open
HugoP707 opened this issue Aug 19, 2020 · 1 comment
Open

Compile time float64 are silently converted to float32 #15203

HugoP707 opened this issue Aug 19, 2020 · 1 comment
Labels
Floating Point VM see also `const` label

Comments

@HugoP707
Copy link
Contributor

HugoP707 commented Aug 19, 2020

Either allow compile time floats to be 64 bit also, or raise an error/warning telling the user about this.

proc interpolate*[T: static[int]](x, y: static[array[T, float32]], xi: static[float32]): static[float32] =
  var
    s: float #float64 doesnt work either
    t: float #float64 doesnt work either

  for i in 0..<T:
    s = 1'f
    t = 1'f
    for j in 0..<T:
      if j != i:
        s = s * (xi - x[j])
        t = t * (x[i] - x[j])
    result = result + ((s / t) * y[i])
      
var res = interpolate([5.float32, 7, 11, 13, 17], [150.float32, 392, 1452, 2366, 5202], 9)
echo(res)


proc interpolateCT*[T: static[int]](x, y: static[array[T, float32]], xi: static[float32]): static[float32] {.compileTime.} =
  var
    s: float #float64 doesnt work either
    t: float #float64 doesnt work either

  for i in 0..<T:
    s = 1'f
    t = 1'f
    for j in 0..<T:
      if j != i:
        s = s * (xi - x[j])
        t = t * (x[i] - x[j])
    result = result + ((s / t) * y[i])
      

const resCT = interpolateCT([5.float32, 7, 11, 13, 17], [150.float32, 392, 1452, 2366, 5202], 9)
echo(resCT)

Output:

809.9999389648438
810.0
@timotheecour
Copy link
Member

duplicate of (closed but un-fixed) #12884

@timotheecour timotheecour added Floating Point VM see also `const` label labels Jul 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Floating Point VM see also `const` label
Projects
None yet
Development

No branches or pull requests

2 participants