Created
September 8, 2016 04:57
-
-
Save cseeger/65daa8a9427e58527f0759726580c7bb to your computer and use it in GitHub Desktop.
Example C-lib binding in Crystal
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Radians | |
class Triangle | |
lib C | |
# In C: double cos(double x) | |
fun cos(value : Float64) : Float64 | |
end | |
def cos(value : Float64) | |
C.cos(value) | |
end | |
end | |
end | |
tri = Radians::Triangle.new | |
puts tri.cos(0.0) | |
puts tri.cos(3.1415926535) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment