float/"float" converted to integer

Messages in english

Modérateur : xcasadmin

compsystems
Messages : 562
Inscription : sam. févr. 04, 2017 11:34 pm
Localisation : Colombia
Contact :

float/"float" converted to integer

Message par compsystems » mer. avr. 24, 2019 10:25 pm

Hello

float as a method or function
float(3), float("3") [enter] returns
3.0, 3.0 # ok

the inverse function

integer as a method or function
integer(3.0), integer("3.1"), [enter] returns
set[3] ? # expected 3, 3 =)

parisse
Messages : 5739
Inscription : mar. déc. 20, 2005 4:02 pm
Contact :

Re: float/"float" converted to integer

Message par parisse » sam. avr. 27, 2019 9:38 am

The converse of float is int in Python mode, or exact or floor depending what you want to do.

compsystems
Messages : 562
Inscription : sam. févr. 04, 2017 11:34 pm
Localisation : Colombia
Contact :

Re: float/"float" converted to integer

Message par compsystems » lun. avr. 29, 2019 8:44 pm

Hello BP,

int(5.1) works well. The syntax of python in Xcas should not be exactly the same as that of the python language, but Xcas should have a concordance or similarity in the following.

The words complex, real, integer, rational, float, should be double function: conversion and data type o domain, for example

assume(a, complex)
complex(3, 4) forms a complex 3 + 4 * i
type(3 + 4 * i)> 'complex'

assume(a, real)
real(3 + 4 * i)> 3

assume(a, float)
float(5)> convert to float 5.0

type (5)> 'integer'
integer (5.0) converts to integer, synonymous with int()

assume(a, rational)
rational (0.5)> 1/2 synonym of float2rational (0.5)

that is to say, it is necessary to add two functions synonymous
integer() of int ()
and rational() of float2rational(0.5)

Répondre