diff --git a/docs/stdlib/safeds/data/tabular/containers/Column.md b/docs/stdlib/safeds/data/tabular/containers/Column.md index 5b877db45..efc843133 100644 --- a/docs/stdlib/safeds/data/tabular/containers/Column.md +++ b/docs/stdlib/safeds/data/tabular/containers/Column.md @@ -18,7 +18,7 @@ A column is a named collection of values. ??? quote "Source code in `column.sdsstub`" ```sds linenums="12" - class Column( + class Column( name: String, data: List = [] ) { diff --git a/docs/stdlib/safeds/lang/Float.md b/docs/stdlib/safeds/lang/Float.md index 471b63a25..789f2efe8 100644 --- a/docs/stdlib/safeds/lang/Float.md +++ b/docs/stdlib/safeds/lang/Float.md @@ -6,6 +6,31 @@ A floating-point number. ??? quote "Source code in `coreClasses.sdsstub`" - ```sds linenums="39" - class Float sub Number + ```sds linenums="46" + class Float sub Number { + /** + * Converts this floating-point number to an integer by truncating the fractional part. + */ + @Pure + @PythonCall("int($this)") + fun toInt() -> i: Int + } + ``` + +## `#!sds fun` toInt {#safeds.lang.Float.toInt data-toc-label='toInt'} + +Converts this floating-point number to an integer by truncating the fractional part. + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `i` | [`Int`][safeds.lang.Int] | - | + +??? quote "Source code in `coreClasses.sdsstub`" + + ```sds linenums="50" + @Pure + @PythonCall("int($this)") + fun toInt() -> i: Int ``` diff --git a/docs/stdlib/safeds/lang/Int.md b/docs/stdlib/safeds/lang/Int.md index 464667f10..2c257ae29 100644 --- a/docs/stdlib/safeds/lang/Int.md +++ b/docs/stdlib/safeds/lang/Int.md @@ -7,5 +7,30 @@ An integer. ??? quote "Source code in `coreClasses.sdsstub`" ```sds linenums="34" - class Int sub Number + class Int sub Number { + /** + * Converts this integer to a floating-point number. + */ + @Pure + @PythonCall("float($this)") + fun toFloat() -> f: Float + } + ``` + +## `#!sds fun` toFloat {#safeds.lang.Int.toFloat data-toc-label='toFloat'} + +Converts this integer to a floating-point number. + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `f` | [`Float`][safeds.lang.Float] | - | + +??? quote "Source code in `coreClasses.sdsstub`" + + ```sds linenums="38" + @Pure + @PythonCall("float($this)") + fun toFloat() -> f: Float ``` diff --git a/docs/stdlib/safeds/lang/List.md b/docs/stdlib/safeds/lang/List.md index 89169047f..2d4607b83 100644 --- a/docs/stdlib/safeds/lang/List.md +++ b/docs/stdlib/safeds/lang/List.md @@ -10,7 +10,7 @@ A list of elements. ??? quote "Source code in `coreClasses.sdsstub`" - ```sds linenums="44" + ```sds linenums="58" class List { /** @@ -34,7 +34,7 @@ Returns the number of elements in the list. ??? quote "Source code in `coreClasses.sdsstub`" - ```sds linenums="49" + ```sds linenums="63" @Pure @PythonCall("len($this)") fun size() -> size: Int diff --git a/docs/stdlib/safeds/lang/Map.md b/docs/stdlib/safeds/lang/Map.md index 96f43256b..0c352b601 100644 --- a/docs/stdlib/safeds/lang/Map.md +++ b/docs/stdlib/safeds/lang/Map.md @@ -11,7 +11,7 @@ A map of keys to values. ??? quote "Source code in `coreClasses.sdsstub`" - ```sds linenums="57" + ```sds linenums="71" class Map { /** @@ -49,7 +49,7 @@ Returns the keys of the map. ??? quote "Source code in `coreClasses.sdsstub`" - ```sds linenums="69" + ```sds linenums="83" @Pure @PythonCall("list($this.keys())") fun keys() -> keys: List @@ -67,7 +67,7 @@ Returns the number of entries in the map. ??? quote "Source code in `coreClasses.sdsstub`" - ```sds linenums="62" + ```sds linenums="76" @Pure @PythonCall("len($this)") fun size() -> size: Int @@ -85,7 +85,7 @@ Returns the values of the map. ??? quote "Source code in `coreClasses.sdsstub`" - ```sds linenums="76" + ```sds linenums="90" @Pure @PythonCall("list($this.values())") fun values() -> values: List diff --git a/docs/stdlib/safeds/lang/String.md b/docs/stdlib/safeds/lang/String.md index e95eda4b6..b14d69895 100644 --- a/docs/stdlib/safeds/lang/String.md +++ b/docs/stdlib/safeds/lang/String.md @@ -4,6 +4,65 @@ Some text. ??? quote "Source code in `coreClasses.sdsstub`" - ```sds linenums="84" - class String + ```sds linenums="98" + class String { + + /** + * Parses the string to a floating-point number. + */ + @Pure + @PythonCall("float($this)") + fun toFloat() -> f: Float + + /** + * Parses the string to an integer. + * + * @param base The base of the integer. + */ + @Pure + @PythonCall("int($this, $base)") + fun toInt(base: Int = 10) -> i: Int + } + ``` + +## `#!sds fun` toFloat {#safeds.lang.String.toFloat data-toc-label='toFloat'} + +Parses the string to a floating-point number. + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `f` | [`Float`][safeds.lang.Float] | - | + +??? quote "Source code in `coreClasses.sdsstub`" + + ```sds linenums="103" + @Pure + @PythonCall("float($this)") + fun toFloat() -> f: Float + ``` + +## `#!sds fun` toInt {#safeds.lang.String.toInt data-toc-label='toInt'} + +Parses the string to an integer. + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `base` | [`Int`][safeds.lang.Int] | The base of the integer. | `#!sds 10` | + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `i` | [`Int`][safeds.lang.Int] | - | + +??? quote "Source code in `coreClasses.sdsstub`" + + ```sds linenums="112" + @Pure + @PythonCall("int($this, $base)") + fun toInt(base: Int = 10) -> i: Int ``` diff --git a/package.json b/package.json index 0fcc5083a..0a08e5542 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,8 @@ "build:clean": "npm run clean && npm run build", "watch": "concurrently -n tsc,cli,lang,vscode,eda -c blue,yellow,red,green \"tsc -b tsconfig.json\" \"npm run watch -w=@safe-ds/cli\" \"npm run watch -w=@safe-ds/lang\" \"npm run watch -w=safe-ds\" \"npm run watch -w=@safe-ds/eda\"", "test": "vitest", - "test-with-coverage": "vitest --coverage" + "test-with-coverage": "vitest --coverage", + "docs:stdlib": "safe-ds document packages/safe-ds-lang/src/resources/builtins -o docs/stdlib" }, "devDependencies": { "@lars-reimann/eslint-config-svelte": "^7.0.0", diff --git a/packages/safe-ds-lang/src/resources/builtins/safeds/lang/coreClasses.sdsstub b/packages/safe-ds-lang/src/resources/builtins/safeds/lang/coreClasses.sdsstub index 1cb6a9a7c..fa45a013b 100644 --- a/packages/safe-ds-lang/src/resources/builtins/safeds/lang/coreClasses.sdsstub +++ b/packages/safe-ds-lang/src/resources/builtins/safeds/lang/coreClasses.sdsstub @@ -26,25 +26,31 @@ class Boolean /** * A number. */ -class Number { +class Number +/** + * An integer. + */ +class Int sub Number { /** - * Converts the number to an integer. + * Converts this integer to a floating-point number. */ @Pure - @PythonCall("int($this)") - fun toInt() -> i: Int + @PythonCall("float($this)") + fun toFloat() -> f: Float } -/** - * An integer. - */ -class Int sub Number - /** * A floating-point number. */ -class Float sub Number +class Float sub Number { + /** + * Converts this floating-point number to an integer by truncating the fractional part. + */ + @Pure + @PythonCall("int($this)") + fun toInt() -> i: Int +} /** * A list of elements. @@ -92,9 +98,16 @@ class Map { class String { /** - * Converts the string to an integer. + * Parses the string to a floating-point number. + */ + @Pure + @PythonCall("float($this)") + fun toFloat() -> f: Float + + /** + * Parses the string to an integer. * - * @base The base of the integer. + * @param base The base of the integer. */ @Pure @PythonCall("int($this, $base)")