Giter Site home page Giter Site logo

Comments (1)

sweep-ai avatar sweep-ai commented on August 10, 2024

Here's the PR! #6.

💎 Sweep Pro: I used GPT-4 to create this ticket. You have 1041 GPT-4 tickets left.


Step 1: 🔍 Code Search

I found the following snippets in your repository. I will now analyze these snippets and come up with a plan.

Some code snippets I looked at (click to expand). If some file is missing from here, you can mention the path in the ticket description.

---
layout: developer-doc
title: Numbers
category: semantics
tags: [semantics, runtime, number]
order: 8
---
# Numbers
In order to enhance the user experience, Enso provides a number hierarchy,
encompassing both integers of unbound size and floating-point decimals.
<!-- MarkdownTOC levels="2,3" autolink="true" -->
- [Number Types](#number-types)
- [Internal Representation](#internal-representation)
- [Type Conversions](#type-conversions)
<!-- /MarkdownTOC -->
## Number Types
The base number type in Enso is `Number`. It includes both integers and
floating-point numbers and is the basic type that should be used whenever
numerical computations are performed. Any method defined on the type `Number` is
automatically available on all types of numeric values.
The hierarchy is further split into the `Integer` and `Decimal` types. `Integer`
is capable of representing values of unbound length. `Decimal` is capable of
representing IEEE 64-bit (double precision) floating numbers.
Any method defined on `Integer` is available for all integers, while any method
defined on `Decimal` is available on all floating-point numbers. Methods defined
on `Integer` or `Decimal` take precedence over methods defined on `Number`, when
name resolution is performed.
## Internal Representation
Integers that can be represented in a 64-bit integer type are represented as
such. When a 64-bit representation would overflow (either by the result of
creating a large number literal or an arithmetic operation), it is represented
in a Java `BigInteger` type, thus becoming significantly slower than the 64-bit
representation.
Decimals are represented using the Java `double` type.
## Type Conversions
Number literals that do not contain a decimal point, are treated as integers.
Other literals are interpreted as decimals (even if the fractional part is 0).
Any arithmetic operation where at least one of the operands is a decimal will
result in a decimal result.
Moreover, the default division operator `/` is implemented as floating-point
division and always returns a decimal. If the desired behavior is integral
division instead, the `Integer.div` method implements it.
Another operator worth noting is the exponentiation operator (`^`). It will
always result in a decimal whenever either operand is decimal or the exponent is
negative. It will also return a float result when the exponent is outside the
64-bit integer range.
There is a `Number.to_decimal` method, that allows converting any number to a
decimal. This is useful in certain high-performance and polyglot applications.

2.max 5
max : Number -> Number
max self that = if self > that then self else that
## A constant holding the floating-point positive infinity.
positive_infinity : Decimal
positive_infinity = Double.POSITIVE_INFINITY
## A constant holding the floating-point negative infinity.
negative_infinity : Decimal
negative_infinity = Double.NEGATIVE_INFINITY
## A constant holding the floating-point Not-a-Number value.
nan : Decimal
nan = Double.NaN
## Checks if the given number is the floating-point Not-a-Number value.
This is needed, because the NaN value will return `False` even when being
compared with itself, so `x == Number.nan` would not work.
is_nan : Boolean
is_nan self = case self of
_ : Decimal -> Double.isNaN self
_ -> False
## Checks if the given number is infinite.
is_infinite : Boolean
is_infinite self = case self of
_ : Decimal -> Double.isInfinite self
_ -> False
## Returns the sign of the number.
signum : Integer
signum self =
if self > 0 then 1 else
if self < 0 then -1 else 0
## Decimal is the type of decimal numbers in Enso.
? Representation
Enso's decimal numbers are represented as IEEE754 double-precision
floating point numbers.
@Builtin_Type
type Decimal
## ALIAS Add, Plus
Adds a decimal and an arbitrary number.
Arguments:
- that: The number to add to this.
Addition in Enso will undergo automatic conversions such that you need
not convert between Integer and Decimal manually.
> Example
Adding 10.1 and 15.
10.1 + 15
+ : Number -> Number
+ self that = @Builtin_Method "Decimal.+"
## ALIAS Subtract, Minus
Subtract an arbitrary number from this.
Arguments:
- that: The number to subtract from this.
> Example
Subtract 5 from 2.78.
2.78 - 5
- : Number -> Number
- self that = @Builtin_Method "Decimal.-"
## ALIAS Multiply, Times, Product
Multiply a decimal by an arbitrary number.
Arguments:
- that: The number to multiply this by.
Multiplication in Enso will undergo automatic conversions such that you
need not convert between Integer and Decimal manually.
> Example
Multiplying 3 by 5.27.
5.27 * 3
* : Number -> Number
* self that = @Builtin_Method "Decimal.*"
## ALIAS Divide
Divides a decimal by an arbitrary number.
Arguments:
- that: The number to divide this by.
Division in Enso will undergo automatic conversions such that you need
not convert between Integer and Decimal manually.
> Example
Dividing 10 by 4.5.
10 / 4.5
/ : Number -> Number
/ self that = @Builtin_Method "Decimal./"
## ALIAS Modulus, Modulo
Computes the remainder when dividing this by that.
Arguments:
- that: The number to divide this by.
Modulus in Enso will undergo automatic conversions such that you need
not convert between Integer and Decimal manually.
> Example
Computing the remainder when dividing 3.5 by 2.
3.5 % 2 == 1.5
> Example
Computing the fractional part of a number.
10.5 % 1.0 == 0.5
% : Number -> Number ! Arithmetic_Error
% self that = @Builtin_Method "Decimal.%"
## ALIAS Power
Compute the result of raising this to the power that.
Arguments:
- that: The exponent.
> Example
Computing 2.2 cubed.
2.2^3
^ : Number -> Number
^ self that = @Builtin_Method "Decimal.^"
## ALIAS Greater Than
Checks if this is greater than that.
Arguments:
- that: The number to compare this against.
> Example
Checking if 10 is greater than 7.3.
10 > 7.3
> : Number -> Boolean
> self that = @Builtin_Method "Decimal.>"
## ALIAS Greater Than or Equal
Checks if this is greater than or equal to that.
Arguments:
- that: The number to compare this against.
> Example
Checking if 10 is greater than or equal to 7.3.
10 >= 7.3
>= : Number -> Boolean
>= self that = @Builtin_Method "Decimal.>="
## ALIAS Less Than
Checks if this is less than that.
Arguments:
- that: The number to compare this against.
> Example
Checking if 10 is less than 7.3.
10 < 7.3
< : Number -> Boolean
< self that = @Builtin_Method "Decimal.<"
## ALIAS Less Than Or Equal
Checks if this is less than or equal to that.

Rounding to `n` digits can be thought of as "rounding to the nearest
multiple of 10^(-n)". For negative decimal counts, this results in
rounding to the nearest positive integer power of 10.
> Example
Round to the nearest integer.
3.3 . round == 3
> Example
Round to two decimal places.
3.1415 . round 2 == 3.14
> Example
Round to the nearest hundred.
1234.0 . round -2 == 1200
> Example
Use Banker's Rounding.
2.5 . round use_bankers=True == 2
round : Integer -> Boolean -> Integer | Decimal ! Illegal_Argument
round self decimal_places=0 use_bankers=False =
Illegal_Argument.handle_java_exception <| Arithmetic_Error.handle_java_exception <|
decimal_result = Core_Math_Utils.roundDouble self decimal_places use_bankers
if decimal_places > 0 then decimal_result else decimal_result.truncate
## Compute the negation of this.
> Example
Negate 5.1 to get -5.1.
5.1.negate
negate : Decimal
negate self = @Builtin_Method "Decimal.negate"
## Convert this to a decimal.
This is a no-op on decimals, but is provided for completeness of the Enso
Number API.
> Example
Convert 5.0 to a decimal to get 5.0.
5.0.to_decimal
to_decimal : Decimal
to_decimal self = @Builtin_Method "Decimal.to_decimal"
## ALIAS From Text
Parses a textual representation of a decimal into a decimal number, returning
a `Number_Parse_Error` if the text does not represent a valid decimal.
Arguments:
- text: The text to parse into a decimal.
- locale: The locale that specifies the format to use when parsing
> Example
Parse the text "7.6" into a decimal number.
Decimal.parse "7.6"
parse : Text -> Locale | Nothing -> Decimal ! Number_Parse_Error
parse text locale=Nothing = case locale of
Nothing -> Panic.catch NumberFormatException (Double.parseDouble text) _->
Error.throw (Number_Parse_Error.Error text)
Locale.Value java_locale -> Panic.catch ParseException ((NumberFormat.getInstance java_locale).parse text) _->
Error.throw (Number_Parse_Error.Error text)
## Integer is the type of integral numbers in Enso. They are of unbounded
size and can grow as large as necessary.
? Representation
For certain operations (such as bitwise logic), the underlying
representation of the number matters. Enso Integers are represented as
signed 2's complement numbers.
? Performance
Integers that fit into 64 bits are represented in memory as 64 bits.
This means that operations on them achieve excellent performance. Once
the integer grows beyond being able to fit in 64 bits, performance will
degrade.
@Builtin_Type
type Integer
## ALIAS Add, Plus
Adds an integer and an arbitrary number.
Arguments:
- that: The number to add to this.
Addition in Enso will undergo automatic conversions such that you need
not convert between Integer and Decimal manually.
> Example
Adding 10 and 15.
10 + 15
+ : Number -> Number
+ self that = @Builtin_Method "Integer.+"
## ALIAS Subtract, Minus
Subtract an arbitrary number from this.
Arguments:
- that: The number to subtract from this.

---
layout: developer-doc
title: Naming
category: syntax
tags: [syntax, naming]
order: 2
---
# Naming
This file describes the syntax for naming language constructs in Enso, as well
as the various rules that names follow.
Names in Enso are restricted to using ASCII characters. This arises from the
simple fact that all names should be easy to type without less common input
methods. Furthermore, we enforce a rigid style for naming. This is in aid of
giving Enso code a uniform identity.
<!-- MarkdownTOC levels="2,3" autolink="true" -->
- [Naming Constructs](#naming-constructs)
- [External Identifiers](#external-identifiers)
- [Pattern Contexts](#pattern-contexts)
- [Localised Naming](#localised-naming)
- [Operator Naming](#operator-naming)
- [Modifier Operators](#modifier-operators)
- [Reserved Names](#reserved-names)
<!-- /MarkdownTOC -->
## Naming Constructs
Given that Enso is dependently-typed, with no artificial separation between the
type and value-level syntaxes, an arbitrary name can refer to both types and
values. This means that naming itself can become a bit of a concern. At first
glance, there is no meaningful syntax-based disambiguation in certain contexts
(such as patterns and type signatures) between introducing a fresh variable, or
an occurrence of one already in scope.
As we still want to have a minimal syntax for such use-cases, Enso enforces the
following rules around naming:
- All identifiers are named as follows. This is known as 'variable' form.
- Each 'word' in the identifier must be lower-case or a number.
- Words in the identifier are separated using `_`.
- Numbers may not occur as the first 'word' in an identifier.
- Mixed-format names are allowed (e.g. `HTTP`, `foO`, `AWS_Profile`, or
`SQLite`).
- We _strongly encourage_ using capitalised identifiers to refer to atoms.
- All names are case-sensitive.
Name resolution obeys the following rules:
- Contexts where it is _ambiguous_ as to whether a name is fresh or should refer
to an identifier in scope are known as _pattern contexts_.
- In a [pattern context](#pattern-contexts), an identifier in referent form will
_always_ refer to a name in scope, whereas an identifier in variable form is
interpreted as the creation of a fresh identifier.
- This behaviour _only_ occurs in pattern contexts. In all other contexts, both
conventions refer to that name already in scope.
- Operator names behave as variable names when placed in a prefix position (e.g.
`+ a b`).
- Operator names behave as referent names when placed in an infix position (e.g.
`a + b`).
- All literals (e.g. `1` and `"Hello"`) are treated as referent names.
Identifiers are introduced by:
- Naming them in a binding (assignments and function arguments).
- Using them in a pattern matching context (free variables).
- Using them in a type ascription (free variables).
### External Identifiers
As Enso has the ability to interface with many other programming languages in a
highly-integrated fashion, it needs to be able to use naming styles from other
languages natively. To do this, we have the concept of a _third_ kind of
identifier, called the 'external' identifier.
An external identifier is one that doesn't match either the variable or referent
forms described above, for example `someJavaName`. It is not an _exclusive_
category, however. Common styles of naming functions in Python, for example,
will usually lex as variable identifiers.
> The actionables for this section are:
>
> - Work out how and where to make a variable/referent distinction for external
> names.

val mainIr =
s"""
|from $namespace.$packageName.Other_Module.Other_Type import method
|""".stripMargin
.createModule(packageQualifiedName.createChild("Main"))
.getIr
mainIr.imports.size shouldEqual 1
mainIr.imports.head
.asInstanceOf[IR.Error.ImportExport]
.reason
.asInstanceOf[
IR.Error.ImportExport.NoSuchConstructor
] shouldEqual IR.Error.ImportExport
.NoSuchConstructor("Other_Type", "method")
}
"result in multiple errors when importing more methods from type" in {
"""
|type Other_Type
| method self = 42
|""".stripMargin
.createModule(packageQualifiedName.createChild("Other_Module"))
val mainIr =
s"""
|from $namespace.$packageName.Other_Module.Other_Type import method, other_method
|""".stripMargin
.createModule(packageQualifiedName.createChild("Main"))
.getIr
mainIr.imports
.take(2)
.map(_.asInstanceOf[IR.Error.ImportExport].reason) shouldEqual List(
IR.Error.ImportExport.NoSuchConstructor("Other_Type", "method"),
IR.Error.ImportExport.NoSuchConstructor("Other_Type", "other_method")
)
}
// TODO[pm]: will be addressed in https://github.com/enso-org/enso/issues/6729
"resolve static method from a module" ignore {
"""
|static_method =
| 42
|""".stripMargin
.createModule(packageQualifiedName.createChild("A_Module"))
val bIr =
s"""
|import $namespace.$packageName.A_Module.static_method
|""".stripMargin
.createModule(packageQualifiedName.createChild("B_Module"))
.getIr
val mainIr =
s"""
|from $namespace.$packageName.A_Module import static_method
|""".stripMargin
.createModule(packageQualifiedName.createChild("Main"))
.getIr
mainIr.imports.head.isInstanceOf[IR.Error.ImportExport] shouldBe false
bIr.imports.head.isInstanceOf[IR.Error.ImportExport] shouldBe false
val mainBindingMap = mainIr.unwrapBindingMap
val bBindingMap = bIr.unwrapBindingMap
mainBindingMap.resolvedImports.size shouldEqual 2
mainBindingMap
.resolvedImports(0)
.target
.asInstanceOf[BindingsMap.ResolvedModule]
.module
.getName
.item shouldEqual "A_Module"
mainBindingMap
.resolvedImports(1)
.target
.asInstanceOf[BindingsMap.ResolvedMethod]


Step 2: 🧐 Snippet Analysis

From looking through the relevant snippets, I decided to make the following modifications:

File Path Proposed Changes
distribution/lib/Standard/Base/0.0.0-dev/src/Data/Numbers.enso Rename the Decimal type to Float and update all its usages in this file.
docs/semantics/numbers.md Update the documentation to replace Decimal with Float.
engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/number/Decimal.java Rename this file to Float.java and update the class name inside the file from Decimal to Float.
engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/number/decimal/ToDecimalNode.java Rename this file to ToFloatNode.java and update the class name inside the file from ToDecimalNode to ToFloatNode.
engine/runtime/src/test/scala/org/enso/compiler/test/semantic/ImportExportTest.scala Update the tests to replace Decimal with Float.

Step 3: 📝 Planning

I have created a plan for writing the pull request. I am now working my plan and coding the required changes to address this issue. Here is the planned pull request:

Rename Decimal type to Float
sweep/rename-decimal-to-float

Description

This PR renames the Decimal type to Float in the Enso codebase. It also updates error messages, documentation, and references to the Decimal type in the Java engine code. Additionally, utilities in the Java engine, such as nodes and packages, are renamed accordingly. Finally, tests are updated to reflect the renaming of Decimal to Float.

Summary of Changes

  • Renamed the Decimal type to Float in the Enso codebase.
  • Updated error messages and documentation to reflect the renaming of Decimal to `Float.
  • Renamed references to the Decimal type in the Java engine code.
  • Renamed utilities in the Java engine, such as nodes and packages, to reflect the renaming of Decimal to Float.
  • Updated tests to reflect the renaming of Decimal to Float.

Step 4: ⌨️ Coding

I have finished coding the issue. I am now reviewing it for completeness.


Step 5: 🔁 Code Review

Success! 🚀


I'm a bot that handles simple bugs and feature requests but I might make mistakes. Please be kind!
Join Our Discord

from enso.

Related Issues (2)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.