You are not logged in.

#1 2007-03-18 04:05:11

skottish
Forum Fellow
From: Here
Registered: 2006-06-16
Posts: 7,942

Python decimal formatting

I'm curious if Python has built in functionality to set numbers to an arbitrary decimal place without using the Decimal class? It seems rather absurd to me to do things like

float(Decimal(str(4.5 + (sin (radians(.062*count))+ 1.0))).quantize(Decimal(10) ** -4))

Casting a float to a string to a Decimal to a float feels like I'm working too hard.

Offline

#2 2007-03-18 04:49:25

cactus
Taco Eater
From: t͈̫̹ͨa͖͕͎̱͈ͨ͆ć̥̖̝o̫̫̼s͈̭̱̞͍̃!̰
Registered: 2004-05-25
Posts: 4,622
Website

Re: Python decimal formatting

are you aiming just for a certain precision in output?
if so..just use sprintf notation...


"Be conservative in what you send; be liberal in what you accept." -- Postel's Law
"tacos" -- Cactus' Law
"t̥͍͎̪̪͗a̴̻̩͈͚ͨc̠o̩̙͈ͫͅs͙͎̙͊ ͔͇̫̜t͎̳̀a̜̞̗ͩc̗͍͚o̲̯̿s̖̣̤̙͌ ̖̜̈ț̰̫͓ạ̪͖̳c̲͎͕̰̯̃̈o͉ͅs̪ͪ ̜̻̖̜͕" -- -̖͚̫̙̓-̺̠͇ͤ̃ ̜̪̜ͯZ͔̗̭̞ͪA̝͈̙͖̩L͉̠̺͓G̙̞̦͖O̳̗͍

Offline

#3 2007-03-18 05:06:54

skottish
Forum Fellow
From: Here
Registered: 2006-06-16
Posts: 7,942

Re: Python decimal formatting

cactus wrote:

are you aiming just for a certain precision in output?

No. These are real number values for Gimp scripts.

Offline

#4 2007-03-18 16:36:50

deficite
Member
From: Augusta, GA
Registered: 2005-06-02
Posts: 693

Re: Python decimal formatting

I know that one problem one runs into with floating decimals is the fact that Base10 numbers don't always translate well to Base2 numbers. I've never worked on GIMP scripts, but can you fill me in on why you have to have only x number of sig figs?

Offline

#5 2007-03-18 19:40:27

skottish
Forum Fellow
From: Here
Registered: 2006-06-16
Posts: 7,942

Re: Python decimal formatting

The problem is is that I don't actually know what the threshold is. If I use this particular function from within Gimp's GUI, it only goes to 3 decimal places. I know for a fact that it will process alright with four or more, but I don't know how many. I'm guessing that it probably doesn't matter, but the nature of my scripts is that I have to maintain tight control over the data. If anything goes wrong, it will distroy my animations.  The videos I'm making take 75+ hours to process, and I never know if something is wrong until I build and watch whole thing.

Offline

Board footer

Powered by FluxBB