Implicit conversion of round numbers to integers (#4542)

Signed-off-by: Nick Cameron <nrc@ncameron.org>
This commit is contained in:
Nick Cameron
2024-11-25 10:50:43 +13:00
committed by GitHub
parent 66f6b741c4
commit 4fe17fe3ab
174 changed files with 1603 additions and 1518 deletions

View File

@ -86,6 +86,7 @@ layout: manual
* [`reduce`](kcl/reduce)
* [`rem`](kcl/rem)
* [`revolve`](kcl/revolve)
* [`round`](kcl/round)
* [`segAng`](kcl/segAng)
* [`segEnd`](kcl/segEnd)
* [`segEndX`](kcl/segEndX)

View File

@ -6,12 +6,10 @@ layout: manual
Convert a number to an integer.
Callers should use floor(), ceil(), or other rounding function first if they care about how numbers with fractional parts are converted. If the number has a fractional part, it's truncated, moving the number towards zero.
If the number is NaN or has a magnitude, either positive or negative, that is too large to fit into the internal integer representation, the result is a runtime error.
DEPRECATED use floor(), ceil(), or round().
```js
int(num: number) -> i64
int(num: number) -> number
```
### Tags
@ -27,7 +25,7 @@ int(num: number) -> i64
### Returns
`i64`
`number`
### Examples

File diff suppressed because one or more lines are too long

46
docs/kcl/round.md Normal file

File diff suppressed because one or more lines are too long

View File

@ -78541,7 +78541,7 @@
{
"name": "int",
"summary": "Convert a number to an integer.",
"description": "Callers should use floor(), ceil(), or other rounding function first if they care about how numbers with fractional parts are converted. If the number has a fractional part, it's truncated, moving the number towards zero.\n\nIf the number is NaN or has a magnitude, either positive or negative, that is too large to fit into the internal integer representation, the result is a runtime error.",
"description": "DEPRECATED use floor(), ceil(), or round().",
"tags": [
"convert"
],
@ -78560,12 +78560,12 @@
],
"returnValue": {
"name": "",
"type": "i64",
"type": "number",
"schema": {
"$schema": "https://spec.openapis.org/oas/3.0/schema/2019-04-02#/definitions/Schema",
"title": "int64",
"type": "integer",
"format": "int64"
"title": "double",
"type": "number",
"format": "double"
},
"required": true
},
@ -96858,10 +96858,6 @@
},
"LiteralValue": {
"anyOf": [
{
"type": "integer",
"format": "int64"
},
{
"type": "number",
"format": "double"
@ -100829,10 +100825,6 @@
},
"LiteralValue": {
"anyOf": [
{
"type": "integer",
"format": "int64"
},
{
"type": "number",
"format": "double"
@ -104804,10 +104796,6 @@
},
"LiteralValue": {
"anyOf": [
{
"type": "integer",
"format": "int64"
},
{
"type": "number",
"format": "double"
@ -110015,11 +110003,9 @@
"properties": {
"instances": {
"description": "The number of total instances. Must be greater than or equal to 1. This includes the original entity. For example, if instances is 2, there will be two copies -- the original, and one new copy. If instances is 1, this has no effect.",
"allOf": [
{
"$ref": "#/components/schemas/Uint"
}
]
"type": "integer",
"format": "uint32",
"minimum": 0.0
},
"center": {
"description": "The center about which to make the pattern. This is a 2D vector.",
@ -110040,13 +110026,6 @@
"description": "Whether or not to rotate the duplicates as they are copied.",
"type": "boolean"
}
},
"definitions": {
"Uint": {
"type": "integer",
"format": "uint32",
"minimum": 0.0
}
}
},
"required": true
@ -110143,11 +110122,6 @@
}
],
"definitions": {
"Uint": {
"type": "integer",
"format": "uint32",
"minimum": 0.0
},
"Path": {
"description": "A path.",
"oneOf": [
@ -112800,11 +112774,9 @@
"properties": {
"instances": {
"description": "The number of total instances. Must be greater than or equal to 1. This includes the original entity. For example, if instances is 2, there will be two copies -- the original, and one new copy. If instances is 1, this has no effect.",
"allOf": [
{
"$ref": "#/components/schemas/Uint"
}
]
"type": "integer",
"format": "uint32",
"minimum": 0.0
},
"axis": {
"description": "The axis around which to make the pattern. This is a 3D vector.",
@ -112835,13 +112807,6 @@
"description": "Whether or not to rotate the duplicates as they are copied.",
"type": "boolean"
}
},
"definitions": {
"Uint": {
"type": "integer",
"format": "uint32",
"minimum": 0.0
}
}
},
"required": true
@ -112947,11 +112912,6 @@
}
],
"definitions": {
"Uint": {
"type": "integer",
"format": "uint32",
"minimum": 0.0
},
"ExtrudeSurface": {
"description": "An extrude surface.",
"oneOf": [
@ -115602,11 +115562,9 @@
"properties": {
"instances": {
"description": "The number of total instances. Must be greater than or equal to 1. This includes the original entity. For example, if instances is 2, there will be two copies -- the original, and one new copy. If instances is 1, this has no effect.",
"allOf": [
{
"$ref": "#/components/schemas/Uint"
}
]
"type": "integer",
"format": "uint32",
"minimum": 0.0
},
"distance": {
"description": "The distance between each repetition. This can also be referred to as spacing.",
@ -115623,13 +115581,6 @@
"maxItems": 2,
"minItems": 2
}
},
"definitions": {
"Uint": {
"type": "integer",
"format": "uint32",
"minimum": 0.0
}
}
},
"required": true
@ -115726,11 +115677,6 @@
}
],
"definitions": {
"Uint": {
"type": "integer",
"format": "uint32",
"minimum": 0.0
},
"Path": {
"description": "A path.",
"oneOf": [
@ -118381,11 +118327,9 @@
"properties": {
"instances": {
"description": "The number of total instances. Must be greater than or equal to 1. This includes the original entity. For example, if instances is 2, there will be two copies -- the original, and one new copy. If instances is 1, this has no effect.",
"allOf": [
{
"$ref": "#/components/schemas/Uint"
}
]
"type": "integer",
"format": "uint32",
"minimum": 0.0
},
"distance": {
"description": "The distance between each repetition. This can also be referred to as spacing.",
@ -118402,13 +118346,6 @@
"maxItems": 3,
"minItems": 3
}
},
"definitions": {
"Uint": {
"type": "integer",
"format": "uint32",
"minimum": 0.0
}
}
},
"required": true
@ -118514,11 +118451,6 @@
}
],
"definitions": {
"Uint": {
"type": "integer",
"format": "uint32",
"minimum": 0.0
},
"ExtrudeSurface": {
"description": "An extrude surface.",
"oneOf": [
@ -137985,10 +137917,6 @@
},
"LiteralValue": {
"anyOf": [
{
"type": "integer",
"format": "int64"
},
{
"type": "number",
"format": "double"
@ -142572,10 +142500,6 @@
},
"LiteralValue": {
"anyOf": [
{
"type": "integer",
"format": "int64"
},
{
"type": "number",
"format": "double"
@ -147160,10 +147084,6 @@
},
"LiteralValue": {
"anyOf": [
{
"type": "integer",
"format": "int64"
},
{
"type": "number",
"format": "double"
@ -151146,10 +151066,6 @@
},
"LiteralValue": {
"anyOf": [
{
"type": "integer",
"format": "int64"
},
{
"type": "number",
"format": "double"
@ -155733,10 +155649,6 @@
},
"LiteralValue": {
"anyOf": [
{
"type": "integer",
"format": "int64"
},
{
"type": "number",
"format": "double"
@ -159704,10 +159616,6 @@
},
"LiteralValue": {
"anyOf": [
{
"type": "integer",
"format": "int64"
},
{
"type": "number",
"format": "double"
@ -164292,10 +164200,6 @@
},
"LiteralValue": {
"anyOf": [
{
"type": "integer",
"format": "int64"
},
{
"type": "number",
"format": "double"
@ -165360,7 +165264,7 @@
"unpublished": false,
"deprecated": false,
"examples": [
"assertEqual(rem(int(7), int(4)), 3, 0.01, \"remainder is 3\")\nassertEqual(rem(int(-7), int(4)), -3, 0.01, \"remainder is 3\")\nassertEqual(rem(int(7), int(-4)), 3, 0.01, \"remainder is 3\")"
"assertEqual(rem(7, 4), 3, 0.01, \"remainder is 3\")\nassertEqual(rem(-7, 4), -3, 0.01, \"remainder is 3\")\nassertEqual(rem(7, -4), 3, 0.01, \"remainder is 3\")"
]
},
{
@ -169249,6 +169153,43 @@
"sketch001 = startSketchOn('XY')\n |> startProfileAt([10, 0], %)\n |> line([5, -5], %)\n |> line([5, 5], %)\n |> lineTo([profileStartX(%), profileStartY(%)], %)\n |> close(%)\n\npart001 = revolve({\n axis = {\n custom = {\n axis = [0.0, 1.0],\n origin = [0.0, 0.0]\n }\n }\n}, sketch001)"
]
},
{
"name": "round",
"summary": "Round a number to the nearest integer.",
"description": "",
"tags": [
"math"
],
"args": [
{
"name": "num",
"type": "number",
"schema": {
"$schema": "https://spec.openapis.org/oas/3.0/schema/2019-04-02#/definitions/Schema",
"title": "double",
"type": "number",
"format": "double"
},
"required": true
}
],
"returnValue": {
"name": "",
"type": "number",
"schema": {
"$schema": "https://spec.openapis.org/oas/3.0/schema/2019-04-02#/definitions/Schema",
"title": "double",
"type": "number",
"format": "double"
},
"required": true
},
"unpublished": false,
"deprecated": false,
"examples": [
"sketch001 = startSketchOn('XZ')\n |> startProfileAt([0, 0], %)\n |> lineTo([12, 10], %)\n |> line([round(7.02986), 0], %)\n |> yLineTo(0, %)\n |> close(%)\n\nextrude001 = extrude(5, sketch001)"
]
},
{
"name": "segAng",
"summary": "Compute the angle (in degrees) of the provided line segment.",

View File

@ -16,7 +16,7 @@ Data for a circular pattern on a 2D sketch.
| Property | Type | Description | Required |
|----------|------|-------------|----------|
| `instances` |[`Uint`](/docs/kcl/types/Uint)| The number of total instances. Must be greater than or equal to 1. This includes the original entity. For example, if instances is 2, there will be two copies -- the original, and one new copy. If instances is 1, this has no effect. | No |
| `instances` |`integer`| The number of total instances. Must be greater than or equal to 1. This includes the original entity. For example, if instances is 2, there will be two copies -- the original, and one new copy. If instances is 1, this has no effect. | No |
| `center` |`[number, number]`| The center about which to make the pattern. This is a 2D vector. | No |
| `arcDegrees` |`number`| The arc angle (in degrees) to place the repetitions. Must be greater than 0. | No |
| `rotateDuplicates` |`boolean`| Whether or not to rotate the duplicates as they are copied. | No |

View File

@ -16,7 +16,7 @@ Data for a circular pattern on a 3D model.
| Property | Type | Description | Required |
|----------|------|-------------|----------|
| `instances` |[`Uint`](/docs/kcl/types/Uint)| The number of total instances. Must be greater than or equal to 1. This includes the original entity. For example, if instances is 2, there will be two copies -- the original, and one new copy. If instances is 1, this has no effect. | No |
| `instances` |`integer`| The number of total instances. Must be greater than or equal to 1. This includes the original entity. For example, if instances is 2, there will be two copies -- the original, and one new copy. If instances is 1, this has no effect. | No |
| `axis` |`[number, number, number]`| The axis around which to make the pattern. This is a 3D vector. | No |
| `center` |`[number, number, number]`| The center about which to make the pattern. This is a 3D vector. | No |
| `arcDegrees` |`number`| The arc angle (in degrees) to place the repetitions. Must be greater than 0. | No |

View File

@ -16,7 +16,7 @@ Data for a linear pattern on a 2D sketch.
| Property | Type | Description | Required |
|----------|------|-------------|----------|
| `instances` |[`Uint`](/docs/kcl/types/Uint)| The number of total instances. Must be greater than or equal to 1. This includes the original entity. For example, if instances is 2, there will be two copies -- the original, and one new copy. If instances is 1, this has no effect. | No |
| `instances` |`integer`| The number of total instances. Must be greater than or equal to 1. This includes the original entity. For example, if instances is 2, there will be two copies -- the original, and one new copy. If instances is 1, this has no effect. | No |
| `distance` |`number`| The distance between each repetition. This can also be referred to as spacing. | No |
| `axis` |`[number, number]`| The axis of the pattern. This is a 2D vector. | No |

View File

@ -16,7 +16,7 @@ Data for a linear pattern on a 3D model.
| Property | Type | Description | Required |
|----------|------|-------------|----------|
| `instances` |[`Uint`](/docs/kcl/types/Uint)| The number of total instances. Must be greater than or equal to 1. This includes the original entity. For example, if instances is 2, there will be two copies -- the original, and one new copy. If instances is 1, this has no effect. | No |
| `instances` |`integer`| The number of total instances. Must be greater than or equal to 1. This includes the original entity. For example, if instances is 2, there will be two copies -- the original, and one new copy. If instances is 1, this has no effect. | No |
| `distance` |`number`| The distance between each repetition. This can also be referred to as spacing. | No |
| `axis` |`[number, number, number]`| The axis of the pattern. | No |

View File

@ -11,16 +11,6 @@ layout: manual
**This schema accepts any of the following:**
**Type:** `integer` (`int64`)
----
**Type:** `number` (`double`)