Skip to content

Commit

Permalink
The Ratio equals operator compares the cross-multiplication of two ra…
Browse files Browse the repository at this point in the history
…tios instead of the data
  • Loading branch information
christianschmitz committed Sep 20, 2024
1 parent 6316156 commit b13d094
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@helios-lang/compiler",
"version": "0.17.0-89",
"version": "0.17.0-90",
"description": "Helios is a Domain Specific Language that compiles to Plutus-Core (i.e. Cardano on-chain validator scripts). Helios is a non-Haskell alternative to Plutus. With this library you can compile Helios scripts and build Cardano transactions, all you need to build 100% client-side dApps for Cardano.",
"main": "src/index.js",
"types": "types/index.d.ts",
Expand Down
14 changes: 13 additions & 1 deletion src/codegen/makeRawFuncs.js
Original file line number Diff line number Diff line change
Expand Up @@ -2049,7 +2049,19 @@ export function makeRawFunctions(simplify, isTestnet) {
)

// Ratio builtins
addDataFuncs("__helios__ratio")
addDataFuncs("__helios__ratio", {
eq: `(a, b) -> {
at = __helios__ratio__top(a);
ab = __helios__ratio__bottom(a);
bt = __helios__ratio__top(b);
bb = __helios__ratio__bottom(b);
__core__equalsInteger(
__core__multiplyInteger(at, bb),
__core__multiplyInteger(bt, ab)
)
}`
})
add(
new RawFunc(
"__helios__ratio__is_valid_data",
Expand Down
4 changes: 2 additions & 2 deletions src/program/multi.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { UserFunc } from "./UserFunc.js"
*/

/**
* All FuncArgs are converted from data to primitive format, so from an external PoV none of them are ignored, and there is no need for an `isIgnored` flag
* Note: all FuncArgs are converted from data to primitive format, so from an external PoV none of them are ignored, and there is no need for an `isIgnored` flag
* @typedef {{
* name: string
* isOptional: boolean
Expand All @@ -39,7 +39,7 @@ import { UserFunc } from "./UserFunc.js"
*/

/**
* if `returns` isn't set, the function returns undefined (i.e. void or unit)
* If `returns` isn't set, the function returns undefined (i.e. void or unit)
* @typedef {{
* name: string
* requiresScriptContext: boolean
Expand Down
2 changes: 1 addition & 1 deletion src/program/version.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const VERSION = "0.17.0-89"
export const VERSION = "0.17.0-90"
15 changes: 15 additions & 0 deletions test/Ratio.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,21 @@ describe("Ratio", () => {
})
})

describe("Ratio == Ratio", () => {
const runner = compileForRun(`testing ratio_eq
func main(a: Ratio, b: Ratio) -> Bool {
a == b
}`)

it("1/1 == 1/1 is true", () => {
runner([ratio(1, 1), ratio(1, 1)], True)
})

it("2/2 == 1/1 is true", () => {
runner([ratio(2, 2), ratio(1, 1)], True)
})
})

describe("Ratio < Ratio", () => {
const runner = compileForRun(`testing ratio_lt
func main(a: Ratio, b: Ratio) -> Bool {
Expand Down

0 comments on commit b13d094

Please sign in to comment.